local string, tostring, tonumber, format, table, math, pairs, ipairs, strsplit, _G = string, tostring, tonumber, format, table, math, pairs, ipairs, strsplit, _G

-- Main Options
function PowaAurasOptions:OptionsOnLoad()
	SlashCmdList["POWA"] = PowaAuras_CommandLine
	SLASH_POWA1 = "/pa"
	SLASH_POWA2 = "/powa"
	PowaAuras_Tooltip:SetOwner(UIParent, "ANCHOR_NONE")
	for i = 1, 5 do
		_G["PowaOptionsList"..i]:SetText(PowaPlayerListe[i])
	end
	for i = 1, 10 do
		_G["PowaOptionsList"..i + 5]:SetText(PowaGlobalListe[i])
	end
	self.Comms:Register()
	PowaBarAuraTextureSlider:SetMinMaxValues(1, self.MaxTextures)
	PowaBarAuraTextureSliderHigh:SetText(self.MaxTextures)
	PowaAurasOptions:SetLockButtonText()
end

function PowaAurasOptions:ResetPositions()
	PowaBarConfigFrame:ClearAllPoints()
	PowaBarConfigFrame:SetPoint("CENTER", "UIParent", "CENTER", 0, 50)
	PowaOptionsFrame:ClearAllPoints()
	PowaOptionsFrame:SetPoint("CENTER", "UIParent", "CENTER", 0, 50)
end

function PowaAurasOptions:UpdateMainOption(hideAll)
	PowaOptionsHeader:SetText("Power Auras "..self.Version)
	PowaMainHideAllButton:SetText(self.Text.nomHide)
	PowaMainTestButton:SetText(self.Text.nomTest)
	PowaEditButton:SetText(self.Text.nomEdit)
	PowaOptionsRename:SetText(self.Text.nomRename)
	PowaEnableButton:SetChecked(PowaMisc.Disabled ~= true)
	PowaDebugButton:SetChecked(PowaMisc.Debug == true)
	PowaTimerRoundingButton:SetChecked(PowaMisc.TimerRoundUp == true)
	PowaAllowInspectionsButton:SetChecked(PowaMisc.AllowInspections == true)
	PowaOptionsTextureCount:SetValue(self.MaxTextures)
	-- Attach the icons
	for i = 1, 24 do
		local k = ((self.CurrentAuraPage - 1) * 24) + i
		local aura = self.Auras[k]
		local icon = _G["PowaIcone"..i]
		-- Icon
		icon.aura = aura
		if aura == nil then
			icon:SetNormalTexture("Interface\\PaperDoll\\UI-Backpack-EmptySlot")
			icon:SetText("")
			icon:SetAlpha(0.33)
		else
			if aura.buffname == "" or aura.buffname == " " then
				icon:SetNormalTexture("Interface\\PaperDoll\\UI-Backpack-EmptySlot")
			elseif aura.icon == "" then
				icon:SetNormalTexture("Interface\\Icons\\Inv_Misc_QuestionMark")
			else
				icon:SetNormalTexture(aura.icon)
			end
			if aura.buffname ~= "" and aura.buffname ~= " " and aura.off then
				icon:SetText("OFF")
			else
				icon:SetText("")
			end
			-- Highlighting the current aura icon
			if self.CurrentAuraId == k then -- The current button
				if aura == nil or aura.buffname == "" or aura.buffname == " " then
					PowaSelected:Hide()
				else
					PowaSelected:SetPoint("CENTER", "PowaIcone"..i, "CENTER")
					PowaSelected:Show()
				end
			end
			-- Descrease alpha for non-visible auras
			if not aura.Showing then
				icon:SetAlpha(0.33)
			else
				if hideAll then
					icon:SetAlpha(0.33)
				else
					icon:SetAlpha(1.0)
				end
			end
		end
	end
	-- Select the current list
	_G["PowaOptionsList"..self.CurrentAuraPage]:SetHighlightTexture("Interface\\Buttons\\UI-Panel-Button-Highlight")
	_G["PowaOptionsList"..self.CurrentAuraPage]:LockHighlight()
end

function PowaAurasOptions:IconClick(owner, button)
	if self.MoveEffect > 0 then -- Move mode
		return
	end
	if ColorPickerFrame:IsVisible() then
		return
	end
	local aura = owner.aura
	if not aura or aura.buffname == "" or aura.buffname == " " then
		return
	end
	if IsShiftKeyDown() then
		if aura.off then
			aura.off = false
			owner:SetText("")
		else
			aura.off = true
			owner:SetText("OFF")
			owner:SetAlpha(0.33)
		end
	elseif IsControlKeyDown() then
		local show, reason = self:TestThisEffect(aura.id, true)
		if show then
			self:Message(self:InsertText(self.Text.nomReasonShouldShow, reason))
		else
			self:Message(self:InsertText(self.Text.nomReasonWontShow, reason))
		end
	elseif IsAltKeyDown() then
		if button == "RightButton" then
			self:IconOnMouseWheel(1)
		else
			self:IconOnMouseWheel(0)
		end
	elseif self.CurrentAuraId == aura.id then
		if button == "RightButton" then
			if not aura.off then
				if not aura.Showing then
					owner:SetAlpha(1.0)
				end
				PowaAurasOptions:OptionEditorTest()
			end
			self:EditorShow()
		else
			if not aura.off then
				if not aura.Showing then
					owner:SetAlpha(1.0)
				else
					owner:SetAlpha(0.33)
				end
				PowaAurasOptions:OptionTest()
			end
		end
	elseif self.CurrentAuraId ~= aura.id then -- Clicked a different button
		self:SetCurrent(owner, aura.id)
		PowaMisc.GroupSize = 1
		if button == "RightButton" then
			if not aura.off then
				if not aura.Showing then
					owner:SetAlpha(1.0)
				end
				PowaAurasOptions:OptionEditorTest()
			end
			PowaBarConfigFrame:Hide()
			self:EditorShow()
		else
			self:InitPage(aura)
		end
	end
end

function PowaAurasOptions:SetCurrent(icon, auraId)
	self.CurrentAuraId = auraId
	if not icon then
		return
	end
	PowaSelected:SetPoint("CENTER", icon, "CENTER")
	PowaSelected:Show()
end

function PowaAurasOptions:IconeEntered(owner)
	local iconID = owner:GetID()
	local k = ((self.CurrentAuraPage - 1) * 24) + iconID
	local aura = self.Auras[k]
	if self.MoveEffect > 0 then
		return
	elseif aura == nil then
		-- If not active
	elseif aura.buffname == "" or aura.buffname == " " then
		-- If no name
	else
		GameTooltip:SetOwner(owner, "ANCHOR_RIGHT")
		aura:AddExtraTooltipInfo(GameTooltip)
		if aura.party then
			GameTooltip:AddLine("("..self.Text.nomCheckParty..")", 1.0, 0.2, 0.2, 1)
		end
		if aura.exact then
			GameTooltip:AddLine("("..self.Text.nomExact..")", 1.0, 0.2, 0.2, 1)
		end
		if aura.mine then
			if aura.bufftype == self.BuffTypes.thenActionReady then
				GameTooltip:AddLine("("..self.Text.nomIgnoreUseable..")", 1.0, 0.2, 0.2, 1)
			elseif aura.bufftype == self.BuffTypes.Buff or aura.bufftype == self.BuffTypes.Debuff then
				GameTooltip:AddLine("("..self.Text.nomMine..")", 1.0, 0.2, 0.2, 1)
			elseif aura.bufftype == self.BuffTypes.TypeBuff or aura.bufftype == self.BuffTypes.TypeDebuff then
				GameTooltip:AddLine("("..self.Text.nomDispellable..")", 1.0, 0.2, 0.2, 1)
			elseif aura.bufftype == self.BuffTypes.Items then
				GameTooltip:AddLine("("..self.Text.nomIgnoreItemUseable..")", 1.0, 0.2, 0.2, 1)
			elseif aura.bufftype == self.BuffTypes.SpellCooldown then
				GameTooltip:AddLine("("..self.Text.nomSpellLearned..")", 1.0, 0.2, 0.2, 1)
			elseif aura.bufftype == self.BuffTypes.SpellAlert then
				GameTooltip:AddLine("("..self.Text.nomCanInterrupt..")", 1.0, 0.2, 0.2, 1)
			end
		end
		if aura.focus then
			GameTooltip:AddLine("("..self.Text.nomCheckFocus..")", 1.0, 0.2, 0.2, 1)
		end
		if aura.raid then
			GameTooltip:AddLine("("..self.Text.nomCheckRaid..")", 1.0, 0.2, 0.2, 1)
		end
		if aura.groupOrSelf then
			GameTooltip:AddLine("("..self.Text.nomCheckGroupOrSelf..")", 1.0, 0.2, 0.2, 1)
		end
		if aura.optunitn then
			GameTooltip:AddLine("("..self.Text.nomCheckOptunitn..")", 1.0, 0.2, 0.2, 1)
		end
		if aura.target then
			GameTooltip:AddLine("("..self.Text.nomCheckTarget..")", 1.0, 0.2, 0.2, 1)
		end
		if aura.targetfriend then
			GameTooltip:AddLine("("..self.Text.nomCheckFriend..")", 0.2, 1.0, 0.2, 1)
		end
		GameTooltip:AddLine(self.Text.aideEffectTooltip, 1.0, 1.0, 1.0, 1)
		GameTooltip:AddLine(self.Text.aideEffectTooltip3, 1.0, 1.0, 1.0, 1)
		GameTooltip:AddLine(self.Text.aideEffectTooltip2, 1.0, 1.0, 1.0, 1)
		GameTooltip:Show()
	end
end

function PowaAurasOptions:MainListClick(owner)
	local listID = owner:GetID()
	if self.MoveEffect == 1 then
		-- Copy the aura
		self:BeginCopyEffect(self.CurrentAuraId, listID)
		return
	elseif self.MoveEffect == 2 then
		-- Move the aura
		self:BeginMoveEffect(self.CurrentAuraId, listID)
		return
	end
	if IsShiftKeyDown() then
		local min = ((listID - 1) * 24) + 1
		local max = min + 23
		local allEnabled = true
		local offText = "OFF"
		for i = min, max do
			local aura = self.Auras[i]
			if (aura and aura.off) then
				allEnabled = false
				offText = ""
				break
			end
		end
		for i = min, max do
			local aura = self.Auras[i]
			if aura then
				local auraIcon = _G["PowaIcone"..(i - min + 1)]
				aura.off = allEnabled
				if self.CurrentAuraPage == listID then
					auraIcon:SetText(offText)
				end
			end
			self.SecondaryAuras[i] = nil
		end
		self.DoCheck.All = true
		return
	end
	if self.CurrentAuraPage ~= listID then
		_G["PowaOptionsList"..self.CurrentAuraPage]:SetHighlightTexture("")
		_G["PowaOptionsList"..self.CurrentAuraPage]:UnlockHighlight()
		PowaMisc.GroupSize = 1
		PowaSelected:Hide()
		self.CurrentAuraPage = listID
		self.CurrentAuraId = ((self.CurrentAuraPage - 1) * 24) + 1
		local aura = self.Auras[self.CurrentAuraId]
		if aura ~= nil and aura.buffname ~= "" and aura.buffname ~= " " then
			self:InitPage(aura)
		else
			self:EditorClose()
		end
		-- Set text for rename
		local currentText = _G["PowaOptionsList"..self.CurrentAuraPage]:GetText()
		if not currentText then
			currentText = ""
		end
		PowaOptionsRenameEditBox:SetText(currentText)
		self:UpdateMainOption()
	end
end

function PowaAurasOptions:MainListEntered(owner)
	local listID = owner:GetID()
	if self.CurrentAuraPage ~= listID then
		if self.MoveEffect > 0 then
			_G["PowaOptionsList"..listID]:SetHighlightTexture("Interface\\Buttons\\UI-Panel-Button-Highlight")
		else
			_G["PowaOptionsList"..listID]:SetHighlightTexture("")
			_G["PowaOptionsList"..listID]:UnlockHighlight()
		end
	end
	if self.MoveEffect == 1 then
		GameTooltip:SetOwner(owner, "ANCHOR_RIGHT")
		GameTooltip:SetText(self.Text.aideCopy, nil, nil, nil, nil, 1)
		GameTooltip:Show()
	elseif self.MoveEffect == 2 then
		GameTooltip:SetOwner(owner, "ANCHOR_RIGHT")
		GameTooltip:SetText(self.Text.aideMove, nil, nil, nil, nil, 1)
		GameTooltip:Show()
	end
end

function PowaAurasOptions:OptionRename()
	PowaOptionsRename:Hide()
	PowaOptionsRenameEditBox:Show()
	local currentText = _G["PowaOptionsList"..self.CurrentAuraPage]:GetText()
	if currentText == nil then
		currentText = ""
	end
	PowaOptionsRenameEditBox:SetText( currentText )
end

function PowaAurasOptions:OptionRenameEdited()
	PowaOptionsRename:Show()
	PowaOptionsRenameEditBox:Hide()
	_G["PowaOptionsList"..self.CurrentAuraPage]:SetText( PowaOptionsRenameEditBox:GetText() )
	if self.CurrentAuraPage > 5 then
		PowaGlobalListe[self.CurrentAuraPage - 5] = PowaOptionsRenameEditBox:GetText()
	else
		PowaPlayerListe[self.CurrentAuraPage] = PowaOptionsRenameEditBox:GetText()
	end
end

function PowaAurasOptions:TriageIcones(nPage)
	local min = ((nPage - 1) * 24) + 1
	local max = min + 23
	-- Hide any auras on this page
	for i = min, max do
		local aura = self.Auras[i]
		if aura then
			aura:Hide()
		end
		self.SecondaryAuras[i] = nil
	end
	local a = min
	for i = min, max do
		if self.Auras[i] then
			if i ~= a then
				self:ReindexAura(i, a)
			end
			if i > a then
				self.Auras[i] = nil
			end
			a = a + 1
		end
	end
	-- Keep global auras in step
	for i = 121, 360 do
		if self.Auras[i] then
			PowaGlobalSet[i] = self.Auras[i]
		else
			PowaGlobalSet[i] = nil
		end
	end
end

function PowaAurasOptions:ReindexAura(oldId, newId)
	self.Auras[newId] = self.Auras[oldId]
	self.Auras[newId].id = newId
	if self.Auras[newId].Timer then
		self.Auras[newId].Timer.id = newId
	end
	if self.Auras[newId].Stacks then
		self.Auras[newId].Stacks.id = newId
	end
	-- Update any multi-id references
	for i = 1, 360 do
		local aura = self.Auras[i]
		if aura then
			if aura.multiids and aura.multiids ~= "" then
				local newMultiids = ""
				local sep = ""
				for multiId in string.gmatch(aura.multiids, "[^/]+") do
					if tonumber(multiId) == oldId then
						newMultiids = newMultiids..sep..tostring(newId)
					else
						newMultiids = newMultiids..sep..multiId
					end
					sep = "/"
				end
				aura.multiids = newMultiids
			end
		end
	end
end

function PowaAurasOptions:Dispose(tableName, key, key2)
	local t = self[tableName]
	if not t or not t[key] then
		return
	end
	if key2 then
		if not t[key][key2] then
			return
		end
		t = t[key]
		key = key2
	end
	if t[key].Hide then
		t[key]:Hide()
	end
	t[key] = nil
end

function PowaAurasOptions:DeleteAura(aura)
	if not aura then
		return
	end
	aura:Hide()
	if aura.Timer then
		aura.Timer:Dispose()
	end
	if aura.Stacks then
		aura.Stacks:Dispose()
	end
	aura:Dispose()
	PowaSelected:Hide()
	if PowaBarConfigFrame:IsVisible() then
		PowaBarConfigFrame:Hide()
	end
	if ColorPickerFrame:IsVisible() then
		ColorPickerFrame:Hide()
	end
	if FontSelectorFrame:IsVisible() then
		FontSelectorFrame:Hide()
	end
	PowaAurasOptions.Models[aura.id] = nil
	PowaAurasOptions.SecondaryModels[aura.id] = nil
	self.Auras[aura.id] = nil
	if aura.id > 120 then
		PowaGlobalSet[aura.id] = nil
	end
end

function PowaAurasOptions:OptionDeleteEffect(auraId)
	if not IsControlKeyDown() then
		return
	end
	local currentAuraId = self.CurrentAuraId
	self:DeleteAura(self.Auras[auraId])
	self:TriageIcones(self.CurrentAuraPage)
	PowaMisc.GroupSize = 1
	self:CalculateAuraSequence()
	if currentAuraId == self:GetNextFreeSlot() then
		self.CurrentAuraId = self:GetNextFreeSlot() - 1
	end
	self:UpdateMainOption()
end

function PowaAurasOptions:GetNextFreeSlot(page)
	if not page then
		page = self.CurrentAuraPage
	end
	local min = ((page - 1) * 24) + 1
	local max = min + 23
	for i = min, max do
		if self.Auras[i] == nil or self.Auras[i].buffname == "" or self.Auras[i].buffname == " " then
			return i
		end
	end
	return nil
end

function PowaAurasOptions:OptionNewEffect()
	local i = self:GetNextFreeSlot()
	if not i then
		self:Message("All aura slots filled.")
		return
	end
	self.CurrentAuraId = i
	self.CurrentAuraPage = self.CurrentAuraPage
	local aura = self:AuraFactory(self.BuffTypes.Buff, i)
	aura:Init()
	self.Auras[i] = aura
	if i > 120 then
		PowaGlobalSet[i] = aura
	end
	self:CalculateAuraSequence()
	aura.Active = true
	aura:CreateFrames()
	self.SecondaryAuras[i] = nil
	self:DisplayAura(i)
	self:UpdateMainOption()
	self:UpdateTimerOptions()
	self:InitPage(aura)
	self:UpdateMainOption()
	if PowaEquipmentSlotsFrame:IsVisible() then
		PowaEquipmentSlotsFrame:Hide()
	end
	if not PowaBarConfigFrame:IsVisible() then
		PowaBarConfigFrame:Show()
		PlaySound("TalentScreenOpen", PowaMisc.SoundChannel)
	end
end

function PowaAurasOptions:ExtractImportValue(valueType, value)
	if string.sub(valueType, 1, 2) == "st" then
		return value
	end
	if value == "false" then
		return false
	elseif value == "true" then
		return true
	end
	return tonumber(value)
end

function PowaAurasOptions:ImportAura(aurastring, auraId, offset)
	local aura = cPowaAura(auraId)
	local trimmed = string.gsub(aurastring, ";%s*", ";")
	local settings = {strsplit(";", trimmed)}
	local importAuraSettings = { }
	local importTimerSettings = { }
	local importStacksSettings = { }
	local hasTimerSettings = false
	local hasStacksSettings = false
	local oldSpellAlertLogic = true
	local hasTypePrefix = false
	if not string.find(aurastring,"Version:", 1, true) then
		hasTypePrefix = true
	else
		hasTypePrefix = string.find(aurastring,"Version:st", 1, true)
	end
	if hasTypePrefix then
		for _, val in ipairs(settings) do
			local key, var = strsplit(":", val)
			local varType = string.sub(var, 1, 2)
			var = string.sub(var, 3)
			if key == "Version" then
				local _, _, major, minor, build = string.find(var, self.VersionPattern)
				if self:VersionGreater({Major = tonumber(major), Minor = tonumber(minor), Build = tonumber(build)}, {Major = 3, Minor = 0, Build = 0}) then
					oldSpellAlertLogic = false
				end
			elseif string.sub(key, 1, 6) == "timer." then
				local key = string.sub(key, 7)
				if key == "InvertAuraBelow" then
					if self:IsNumeric(var) then
						importAuraSettings[key] = self:ExtractImportValue(varType, var)
					end
				else
					importTimerSettings[key] = self:ExtractImportValue(varType, var)
					hasTimerSettings = true
				end
			elseif string.sub(key, 1, 7) == "stacks." then
				importStacksSettings[string.sub(key, 8)] = self:ExtractImportValue(varType, var)
				hasStacksSettings = true
			else
				importAuraSettings[key] = self:ExtractImportValue(varType, var)
			end
		end
	else
		for _, val in ipairs(settings) do
			local key, var = strsplit(":", val)
			oldSpellAlertLogic = false
			if key == "Version" then
				-- Do nothing
			elseif string.sub(key,1,6) == "timer." then
				key = string.sub(key,7)
				if cPowaTimer.ExportSettings[key] ~= nil then
					importTimerSettings[key] = self:ExtractImportValue(type(cPowaTimer.ExportSettings[key]), var)
					hasTimerSettings = true
				end
			elseif string.sub(key, 1, 7) == "stacks." then
				key = string.sub(key, 8)
				if cPowaStacks.ExportSettings[key] ~= nil then
					importStacksSettings[key] = self:ExtractImportValue(type(cPowaStacks.ExportSettings[key]), var)
					hasStacksSettings = true
				end
			else
				if cPowaAura.ExportSettings[key] ~= nil then
					importAuraSettings[key] = self:ExtractImportValue(type(cPowaAura.ExportSettings[key]), var)
				end
			end
		end
	end
	for k, v in pairs(aura) do
		if importAuraSettings[k] ~= nil then
			local varType = type(v)
			if k == "combat" then
				if importAuraSettings[k] == 0 then
					aura[k] = 0
				elseif importAuraSettings[k] == 1 then
					aura[k] = true
				elseif importAuraSettings[k] == 2 then
					aura[k] = false
				else
					aura[k] = importAuraSettings[k]
				end
			elseif k == "isResting" then
				if importAuraSettings.ignoreResting == true then
					aura[k] = true
				elseif importAuraSettings.ignoreResting == true then
					aura[k] = 0
				else
					aura[k] = importAuraSettings[k]
				end
			elseif k == "inRaid" then
				if importAuraSettings.isinraid == true then
					aura[k] = true
				elseif importAuraSettings.isinraid == false then
					aura[k] = 0
				else
					aura[k] = importAuraSettings[k]
				end
			elseif k == "multiids" and offset then
				local newMultiids = ""
				local sep = ""
				for multiId in string.gmatch(importAuraSettings[k], "[^/]+") do
					multiId = cPowaAura:Trim(multiId)
					local negate = ""
					if string.sub(multiId, 1, 1) == "!" then
						multiId = string.sub(multiId, 2)
						negate = "!"
					end
					local multiIdNumber = tonumber(multiId)
					if multiIdNumber then
						newMultiids = newMultiids..sep..negate..tostring(offset + multiIdNumber)
						sep = "/"
					end
				end
				aura[k] = newMultiids
			elseif k == "icon" then
				if string.find(string.lower(importAuraSettings[k]), string.lower(PowaAurasOptions.IconSource), 1, true) == 1 then
					if importAuraSettings[k] == "" then
						aura[k] = "Interface\\Icons\\Inv_Misc_QuestionMark"
					else
						aura[k] = importAuraSettings[k]
					end
				else
					if importAuraSettings[k] == "" then
						aura[k] = "Interface\\Icons\\Inv_Misc_QuestionMark"
					else
						aura[k] = PowaAurasOptions.IconSource..importAuraSettings[k]
					end
				end
			elseif varType == "string" or varType == "boolean" or varType == "number" and k ~= "id" then
				aura[k] = importAuraSettings[k]
			end
		end
	end
	if aura.bufftype == self.BuffTypes.Combo then -- Backwards compatability
		if string.len(aura.buffname) > 1 and string.find(aura.buffname, "/", 1, true) == nil then
			local newBuffName = string.sub(aura.buffname, 1, 1)
			for i = 2, string.len(aura.buffname) do
				newBuffName = newBuffName.."/"..string.sub(aura.buffname, i, i)
			end
			aura.buffname = newBuffName
		end
	elseif aura.bufftype == self.BuffTypes.SpellAlert then
		if oldSpellAlertLogic then
			if aura.target then
				aura.groupOrSelf = true
			elseif aura.targetfriend then
				aura.targetfriend = false
			end
		end
	end
	if importAuraSettings.timer then -- Backwards compatability
		aura.Timer = cPowaTimer(aura)
	end
	if hasTimerSettings then
		aura.Timer = cPowaTimer(aura, importTimerSettings)
	end
	if hasStacksSettings then
		aura.Stacks = cPowaStacks(aura, importStacksSettings)
	end
	return self:AuraFactory(aura.bufftype, auraId, aura)
end

function PowaAurasOptions:CreateNewAuraFromImport(auraId, importString, updateLink)
	if importString == nil or importString == "" then
		return
	end
	self.Auras[auraId] = self:ImportAura(importString, auraId, updateLink)
	self.Auras[auraId]:Init()
	self:CalculateAuraSequence()
	if auraId > 120 then
		PowaGlobalSet[auraId] = self.Auras[auraId]
	end
end

function PowaAurasOptions:CreateNewAuraSetFromImport(importString)
	if not importString or importString == "" then
		return
	end
	local min = ((self.CurrentAuraPage - 1) * 24) + 1
	local max = min + 23
	for i = min, max do
		if self.Auras[i] then
			self:DeleteAura(self.Auras[i])
		end
	end
	local auraId = min
	local offset
	local setName
	for k, v in string.gmatch(importString, "([^\n=@]+)=([^@]+)@") do
		if k == "Set" then
			setName = v
		else
			if not offset then
				local _, _, oldAuraId = string.find(k, "(%d+)")
				if self:IsNumeric(oldAuraId) then
					offset = min - oldAuraId
				end
			end
			self.Auras[auraId] = self:ImportAura(v, auraId, offset)
			if auraId > 120 then
				PowaGlobalSet[auraId] = self.Auras[auraId]
			end
			auraId = auraId + 1
		end
	end
	if setName then
		local nameFound = false
		for i = 1, 5 do
			if (PowaPlayerListe[i] == setName) then
				nameFound = true
			end
		end
		for i = 1, 10 do
			if (PowaGlobalListe[i] == setName) then
				nameFound = true
			end
		end
		if not nameFound then
			_G["PowaOptionsList"..self.CurrentAuraPage]:SetText( setName )
			if self.CurrentAuraPage > 5 then
				PowaGlobalListe[self.CurrentAuraPage - 5] = setName
			else
				PowaPlayerListe[self.CurrentAuraPage] = setName
			end
		end
	end
	self:CalculateAuraSequence()
	self:UpdateMainOption()
end

function PowaAurasOptions:OptionImportEffect()
	local i = self:GetNextFreeSlot()
	if not i then
		self:Message("All aura slots filled.")
		return
	end
	self.ImportAuraId = i
	StaticPopup_Show("POWERAURAS_IMPORT_AURA")
end

function PowaAurasOptions:CreateAuraSetString()
	local setString = "Set="
	if self.CurrentAuraPage > 5 then
		setString = setString..PowaGlobalListe[self.CurrentAuraPage - 5]
	else
		setString = setString..PowaPlayerListe[self.CurrentAuraPage]
	end
	setString = setString.."@"
	local min = ((self.CurrentAuraPage - 1) * 24) + 1
	local max = min + 23
	for i = min, max do
		if self.Auras[i] ~= nil and self.Auras[i].buffname ~= "" and self.Auras[i].buffname ~= " " then
			setString = setString.."\nAura["..tostring(i).."]="..self.Auras[i]:CreateAuraString(true).."@"
		end
	end
	return setString
end

function PowaAurasOptions:OptionImportSet()
	StaticPopup_Show("POWERAURAS_IMPORT_AURA_SET")
end

function PowaAurasOptions:ImportAuraDialogInit()
	StaticPopupDialogs["POWERAURAS_IMPORT_AURA"] = {
		text = self.Text.aideImport,
		button1 = self.Text.ImportDialogAccept,
		button2 = self.Text.ImportDialogCancel,
		hasEditBox = 1,
		maxLetters = self.ExportMaxSize,
		--hasWideEditBox = 1,
		editBoxWidth = self.ExportWidth,
		OnAccept = function(self)
			PowaAurasOptions:CreateNewAuraFromImport(PowaAurasOptions.ImportAuraId, self.editBox:GetText())
			self:Hide()
		end,
		OnShow = function(self)
			self.editBox:SetFocus()
		end,
		OnHide = function(self)
			ChatEdit_FocusActiveWindow()
			self.editBox:SetText("")
			--PowaAurasOptions:DisplayAura(PowaAurasOptions.CurrentAuraId)
			PowaAurasOptions:UpdateMainOption()
		end,
		EditBoxOnEnterPressed = function(self)
			local parent = self:GetParent()
			PowaAurasOptions:CreateNewAuraFromImport(PowaAurasOptions.ImportAuraId, parent.editBox:GetText())
			parent:Hide()
		end,
		EditBoxOnEscapePressed = function(self)
			self:GetParent():Hide()
		end,
		timeout = 0,
		exclusive = 1,
		whileDead = 1,
		hideOnEscape = 1
	}
	StaticPopupDialogs["POWERAURAS_IMPORT_AURA_SET"] = {
		text = self.Text.aideImportSet,
		button1 = self.Text.ImportDialogAccept,
		button2 = self.Text.ImportDialogCancel,
		hasEditBox = 1,
		maxLetters = self.ExportMaxSize * 24,
		--hasWideEditBox = 1,
		editBoxWidth = self.ExportWidth,
		OnAccept = function(self)
			PowaAurasOptions:CreateNewAuraSetFromImport(self.editBox:GetText())
			self:Hide()
		end,
		OnShow = function(self)
			self.editBox:SetFocus()
		end,
		OnHide = function(self)
			ChatEdit_FocusActiveWindow()
			self.editBox:SetText("")
			--PowaAurasOptions:DisplayAura(PowaAurasOptions.CurrentAuraId)
			PowaAurasOptions:UpdateMainOption()
		end,
		EditBoxOnEnterPressed = function(self)
			local parent = self:GetParent()
			PowaAurasOptions:CreateNewAuraSetFromImport(parent.editBox:GetText())
			parent:Hide()
		end,
		EditBoxOnEscapePressed = function(self)
			self:GetParent():Hide()
		end,
		timeout = 0,
		exclusive = 1,
		whileDead = 1,
		hideOnEscape = 1
	}
end

-- Export Dialog
function PowaAurasOptions:OptionExportEffect()
	if self.Auras[self.CurrentAuraId] then
		PowaAuraExportDialogCopyBox:SetText(PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId]:CreateAuraString())
		PowaAuraExportDialog.sendType = 1
		StaticPopupSpecial_Show(PowaAuraExportDialog)
	end
end

function PowaAurasOptions:OptionExportSet()
	PowaAuraExportDialogCopyBox:SetText(PowaAurasOptions:CreateAuraSetString())
	PowaAuraExportDialog.sendType = 2
	StaticPopupSpecial_Show(PowaAuraExportDialog)
end

function PowaAurasOptions:SetDialogTimeout(dialog, timeout)
	if dialog.statusTimeoutLength == timeout then
		if timeout == 0 then
			dialog:SetScript("OnUpdate", nil)
		end
		return
	end
	dialog.statusTimeoutLength = timeout
	dialog.statusTimeout = time() + timeout
	if dialog.statusTimeoutLength > 0 then
		dialog:SetScript("OnUpdate", function(dialog)
			if dialog.statusTimeout <= time() then
				dialog.errorReason = 3
				dialog:SetStatus(3)
			elseif dialog.UpdateTimerDisplay then
				dialog:UpdateTimerDisplay()
			end
		end)
	else
		dialog:SetScript("OnUpdate", nil)
	end
end

function PowaAurasOptions:ExportDialogInit(self)
	self.exclusive = 1
	self.whileDead = 1
	self.hideOnEscape = 1
	self.timeout = 0
	self.errorReason = 1
	self.sendDisplay = ""
	self.sendStatus = 1
	self.sendString = nil
	self.sendTo = nil
	self.sendType = nil
	self.statusTimeout = 0
	self.statusTimeoutLength = 0
	self.AcceptButton = PowaAuraExportDialogSendButton
	self.CancelButton = PowaAuraExportDialogCancelButton
	self.Title = PowaAuraExportDialogSendTitle
	self.EditBox = PowaAuraExportDialogSendBox
	PowaAuraExportDialogTopTitle:SetText(PowaAurasOptions.Text.ExportDialogTopTitle)
	PowaAuraExportDialogCopyTitle:SetText(PowaAurasOptions.Text.ExportDialogCopyTitle)
	PowaAuraExportDialogMidTitle:SetText(PowaAurasOptions.Text.ExportDialogMidTitle)
	PowaAuraExportDialogSendTitle:SetText(PowaAurasOptions.Text.ExportDialogSendTitle1)
	PowaAuraExportDialogSendButton:SetText(PowaAurasOptions.Text.ExportDialogSendButton1)
	PowaAuraExportDialogCancelButton:SetText(PowaAurasOptions.Text.ExportDialogCancelButton)
	self.SetStatus = function(self, status)
		if not PowaAurasOptions.Comms:IsRegistered() then
			status = 6
		end
		self.sendStatus = status or self.sendStatus or 1
		if self.sendStatus == 1 then
			self.Title:SetText(PowaAurasOptions.Text.ExportDialogSendTitle1)
			self.AcceptButton:SetText(PowaAurasOptions.Text.ExportDialogSendButton1)
			self.CancelButton:Enable()
			self.EditBox:Show()
			PowaAurasOptions:SetDialogTimeout(self, 0)
		elseif self.sendStatus >= 2 then
			self.AcceptButton:SetText(PowaAurasOptions.Text.ExportDialogSendButton2)
			self.EditBox:Hide()
			self.AcceptButton:Disable()
			self.CancelButton:Disable()
			if self.sendStatus == 2 then
				PowaAurasOptions:SetDialogTimeout(self, 30)
				self.Title:SetText(format(PowaAurasOptions.Text.ExportDialogSendTitle2, self.sendDisplay, (self.statusTimeout - time())))
			elseif self.sendStatus == 3 then
				local errstring = PowaAurasOptions.Text.ExportDialogSendTitle3c -- Defaults to timeout message
				if self.errorReason == 1 then
					errstring = PowaAurasOptions.Text.ExportDialogSendTitle3a -- In combat
				elseif self.errorReason == 2 then
					errstring = PowaAurasOptions.Text.ExportDialogSendTitle3b -- Autodeclining offers
				elseif self.errorReason == 4 then
					errstring = PowaAurasOptions.Text.ExportDialogSendTitle3d -- Busy with another request
				elseif self.errorReason == 5 then
					errstring = PowaAurasOptions.Text.ExportDialogSendTitle3e -- Declined offer
				end
				self.Title:SetText(format(errstring, self.sendDisplay))
				self.AcceptButton:Enable()
				self.CancelButton:Enable()
				PowaAurasOptions:SetDialogTimeout(self, 0)
			elseif self.sendStatus == 4 then
				self.Title:SetText(PowaAurasOptions.Text.ExportDialogSendTitle4)
				PowaAurasOptions:SetDialogTimeout(self, 10)
			elseif self.sendStatus == 5 then
				self.Title:SetText(PowaAurasOptions.Text.ExportDialogSendTitle5)
				PowaAurasOptions:SetDialogTimeout(self, 0)
				self.AcceptButton:Enable()
				self.CancelButton:Enable()
			elseif self.sendStatus == 6 then
				self.Title:SetText(PowaAurasOptions.Text.aideCommsRegisterFailure)
				self.CancelButton:Enable()
				PowaAurasOptions:SetDialogTimeout(self, 0)
			end
		end
	end
	self.UpdateTimerDisplay = function(self)
		if self.sendStatus == 2 then
			self.Title:SetText(format(PowaAurasOptions.Text.ExportDialogSendTitle2, self.sendDisplay, (self.statusTimeout - time())))
		end
	end
	self.OnShow = function(self)
		self:SetStatus()
		self.sendString = PowaAuraExportDialogCopyBox:GetText()
		PowaAuraExportDialogCopyBox:HighlightText()
		PowaAuraExportDialogCopyBox:SetFocus()
	end
	self.OnAccept = function(self)
		self.sendTo = self.EditBox:GetText()
		self.sendDisplay = self.sendTo
		if self.sendStatus == 1 then
			self:SetStatus(2)
			PowaComms:SendAddonMessage("EXPORT_REQUEST", self.sendType, self.sendTo)
		else
			self:SetStatus(1)
		end
	end
	self.OnCancel = function(self)
		StaticPopupSpecial_Hide(self)
	end
	PowaComms:AddHandler("EXPORT_REJECT", function(_, data, from)
		if PowaAuraExportDialog.sendTo == from then
			if PowaMisc.Debug then
				PowaAurasOptions:ShowText("Comms: EXPORT_REJECT from "..from)
			end
			PowaAuraExportDialog.sendTo = nil
			PowaAuraExportDialog.errorReason = tonumber((data or 1), 10)
			PowaAuraExportDialog:SetStatus(3)
		end
	end)
	PowaComms:AddHandler("EXPORT_ACCEPT", function(_, _, from)
		if PowaAuraExportDialog.sendTo == from then
			if PowaMisc.Debug then
				PowaAurasOptions:ShowText("Comms: EXPORT_ACCEPT from "..from)
			end
			PowaAuraExportDialog:SetStatus(4)
			PowaComms:SendAddonMessage("EXPORT_DATA", PowaAuraExportDialog.sendString, from)
			PowaAuraExportDialog:SetStatus(5)
		end
	end)
end

-- Cross-Client Import Dialog
function PowaAurasOptions:PlayerImportDialogInit(self)
	self.exclusive = 1
	self.whileDead = 1
	self.hideOnEscape = 1
	self.timeout = 0
	self.errorReason = 1
	self.receiveDisplay = ""
	self.receiveFrom = nil
	self.receiveStatus = 1
	self.receiveString = nil
	self.receiveType = nil
	self.statusTimeout = 0
	self.statusTimeoutLength = 0
	self.AcceptButton = PowaAuraPlayerImportDialogAcceptButton
	self.CancelButton = PowaAuraPlayerImportDialogCancelButton
	self.Title = PowaAuraPlayerImportDialogDescTitle
	self.Warning = PowaAuraPlayerImportDialogWarningTitle
	PowaAuraPlayerImportDialogTopTitle:SetText(PowaAurasOptions.Text.PlayerImportDialogTopTitle)
	PowaAuraPlayerImportDialogDescTitle:SetText(PowaAurasOptions.Text.PlayerImportDialogDescTitle1)
	PowaAuraPlayerImportDialogWarningTitle:SetText(PowaAurasOptions.Text.PlayerImportDialogWarningTitle)
	PowaAuraPlayerImportDialogAcceptButton:SetText(PowaAurasOptions.Text.PlayerImportDialogAcceptButton1)
	PowaAuraPlayerImportDialogCancelButton:SetText(PowaAurasOptions.Text.PlayerImportDialogCancelButton1)
	self.SetStatus = function(self, status)
		self.receiveStatus = status or self.receiveStatus or 1
		if self.receiveStatus == 1 then
			self.AcceptButton:Enable()
			self.CancelButton:Enable()
			self.CancelButton:SetText(PowaAurasOptions.Text.PlayerImportDialogCancelButton1)
			self.AcceptButton:SetText(PowaAurasOptions.Text.PlayerImportDialogAcceptButton1)
			self.Title:SetText(format(PowaAurasOptions.Text.PlayerImportDialogDescTitle1, self.receiveDisplay))
			PowaAurasOptions:SetDialogTimeout(self, 25)
			self.Warning:Hide()
		elseif self.receiveStatus >= 2 then
			self.AcceptButton:Disable()
			self.CancelButton:Disable()
			self.CancelButton:SetText(PowaAurasOptions.Text.ExportDialogCancelButton)
			self.Warning:Hide()
			if self.receiveStatus == 2 then
				self.Title:SetText(PowaAurasOptions.Text.PlayerImportDialogDescTitle2)
				PowaAurasOptions:SetDialogTimeout(self, 10)
			elseif self.receiveStatus == 3 then
				self.Title:SetText(PowaAurasOptions.Text.PlayerImportDialogDescTitle3)
				self.CancelButton:Enable()
				PowaAurasOptions:SetDialogTimeout(self, 0)
			elseif self.receiveStatus == 4 then
				self.Title:SetText(PowaAurasOptions.Text.PlayerImportDialogDescTitle4)
				for i = 1, 15 do
					_G["PowaOptionsList"..i.."Glow"]:SetVertexColor(0.5, 0.5, 0.5)
					_G["PowaOptionsList"..i.."Glow"]:Show()
				end
				if self.receiveType == 2 then
					self.Warning:Show()
				end
				self.AcceptButton:SetText(PowaAurasOptions.Text.PlayerImportDialogAcceptButton2)
				PowaAurasOptions:SetDialogTimeout(self, 0)
				self.AcceptButton:Enable()
				self.CancelButton:Enable()
				PowaOptionsFrame:Show()
			elseif self.receiveStatus == 5 then
				self.Title:SetText(PowaAurasOptions.Text.PlayerImportDialogDescTitle5)
				for i = 1, 15 do
					_G["PowaOptionsList"..i.."Glow"]:Hide()
				end
				self.AcceptButton:SetText(PowaAurasOptions.Text.PlayerImportDialogAcceptButton2)
				PowaAurasOptions:SetDialogTimeout(self, 0)
				self.AcceptButton:Disable()
				self.CancelButton:Enable()
			elseif self.receiveStatus == 6 then
				self.Title:SetText(PowaAurasOptions.Text.PlayerImportDialogDescTitle6)
				self.AcceptButton:SetText(PowaAurasOptions.Text.PlayerImportDialogAcceptButton2)
				self.CancelButton:SetText(PowaAurasOptions.Text.ExportDialogSendButton2)
				PowaAurasOptions:SetDialogTimeout(self, 0)
				self.AcceptButton:Disable()
				self.CancelButton:Enable()
			end
		end
	end
	self.OnShow = function(self)
		self:SetStatus()
	end
	self.OnHide = function(self)
		if self.receiveStatus == 1 and self.receiveFrom then
			PowaComms:SendAddonMessage("EXPORT_REJECT", 5, self.receiveFrom)
		end
		self.receiveFrom = nil
		self.receiveDisplay = ""
		self.receiveString = nil
	end
	self.OnAccept = function(self)
		if self.receiveStatus == 1 and self.receiveFrom then
			PowaComms:SendAddonMessage("EXPORT_ACCEPT", "", self.receiveFrom)
			self:SetStatus(2)
		elseif self.receiveStatus == 4 and self.receiveFrom then
			if self.receiveType == 1 then
				local i = PowaAurasOptions:GetNextFreeSlot()
				if not i then
					self:SetStatus(6)
					return
				end
				PowaAurasOptions:CreateNewAuraFromImport(i, PowaAuraPlayerImportDialog.receiveString)
				PowaAurasOptions:UpdateMainOption()
			elseif self.receiveType == 2 then
				PowaAurasOptions:CreateNewAuraSetFromImport(PowaAuraPlayerImportDialog.receiveString)
			end
			self:SetStatus(5)
		end
	end
	self.OnCancel = function(self)
		if self.receiveStatus == 6 then
			self:SetStatus(4)
			return
		end
		StaticPopupSpecial_Hide(self)
	end
	PowaComms:AddHandler("EXPORT_REQUEST", function(_, data, from)
		if PowaAuraPlayerImportDialog.receiveFrom then
			if PowaMisc.Debug then
				PowaAurasOptions:ShowText("Comms: Rejected EXPORT_REQUEST - Busy.")
			end
			PowaComms:SendAddonMessage("EXPORT_REJECT", 4, from)
			return
		end
		if InCombatLockdown() then
			if PowaMisc.Debug then
				PowaAurasOptions:ShowText("Comms: Rejected EXPORT_REQUEST - In combat.")
			end
			PowaComms:SendAddonMessage("EXPORT_REJECT", 1, from)
			return
		end
		if PowaGlobalMisc.BlockIncomingAuras == true then
			if PowaMisc.Debug then
				PowaAurasOptions:ShowText("Comms: Rejected EXPORT_REQUEST - BlockIncomingAuras = true.")
			end
			PowaComms:SendAddonMessage("EXPORT_REJECT", 2, from)
			return
		end
		PowaAuraPlayerImportDialog:SetPoint("CENTER")
		PowaAuraPlayerImportDialog:SetStatus(1)
		PowaAuraPlayerImportDialog.receiveFrom = from
		PowaAuraPlayerImportDialog.receiveDisplay = from
		PowaAuraPlayerImportDialog.receiveType = tonumber(data, 10)
		StaticPopupSpecial_Show(PowaAuraPlayerImportDialog)
	end)
	PowaComms:AddHandler("EXPORT_DATA", function(_, data, from)
		if PowaAuraPlayerImportDialog.receiveFrom == from then
			if PowaMisc.Debug then
				PowaAurasOptions:ShowText("Comms: Receiving EXPORT_DATA")
			end
			PowaAuraPlayerImportDialog:SetStatus(4)
			PowaAuraPlayerImportDialog.receiveString = data
		end
	end)
end

function PowaAurasOptions:DisableMoveMode()
	PowaOptionsMove:UnlockHighlight()
	PowaOptionsCopy:UnlockHighlight()
	self.MoveEffect = 0
	for i = 1, 15 do
		_G["PowaOptionsList"..i.."Glow"]:Hide()
	end
	PowaOptionsMove:Enable()
	PowaOptionsCopy:Enable()
	PowaOptionsRename:Enable()
	PowaEditButton:Enable()
	PowaMainTestButton:Enable()
	PowaMainHideAllButton:Enable()
	PowaOptionsSelectorNew:Enable()
	PowaOptionsSelectorDelete:Enable()
end

function PowaAurasOptions:OptionMoveEffect(isMove)
	if not self.Auras[self.CurrentAuraId] or self.Auras[self.CurrentAuraId].buffname == "" or self.Auras[self.CurrentAuraId].buffname == " " then
		return
	end
	-- Set glow for lists
	if self.MoveEffect == 0 then
		if isMove then
			self.MoveEffect = 2
			PowaOptionsMove:LockHighlight()
			PowaOptionsCopy:Disable()
		else
			self.MoveEffect = 1
			PowaOptionsCopy:LockHighlight()
			PowaOptionsMove:Disable()
		end
		for i = 1, 15 do
			_G["PowaOptionsList"..i.."Glow"]:SetVertexColor(0.5, 0.5, 0.5)
			_G["PowaOptionsList"..i.."Glow"]:Show()
		end
		PowaOptionsRename:Disable()
		PowaEditButton:Disable()
		PowaMainTestButton:Disable()
		PowaMainHideAllButton:Disable()
		PowaOptionsSelectorNew:Disable()
		PowaOptionsSelectorDelete:Disable()
	else
		self:DisableMoveMode()
	end
end

function PowaAurasOptions:BeginMoveEffect(Pfrom, ToPage)
	local i = self:GetNextFreeSlot(ToPage)
	if not i then
		self:Message("All aura slots filled.")
		return
	end
	self:DoCopyEffect(Pfrom, i, true)
	self:TriageIcones(self.CurrentAuraPage)
	self:CalculateAuraSequence()
	self.CurrentAuraId = ((self.CurrentAuraPage - 1) * 24) + 1
	self:DisableMoveMode()
	self:UpdateMainOption()
end

function PowaAurasOptions:BeginCopyEffect(Pfrom, ToPage)
	local i = self:GetNextFreeSlot(ToPage)
	if not i then
		self:Message("All aura slots filled.")
		return
	end
	self:DoCopyEffect(Pfrom, i, false)
	self.CurrentAuraId = i
	self:DisableMoveMode()
	self:UpdateMainOption()
end

function PowaAurasOptions:DoCopyEffect(idFrom, idTo, isMove)
	self.Auras[idTo] = self:AuraFactory(self.Auras[idFrom].bufftype, idTo, self.Auras[idFrom])
	self.Auras[idTo]:Init()
	if self.Auras[idFrom].Timer then
		self.Auras[idTo].Timer = cPowaTimer(self.Auras[idTo], self.Auras[idFrom].Timer)
	end
	if self.Auras[idFrom].Stacks then
		self.Auras[idTo].Stacks = cPowaStacks(self.Auras[idTo], self.Auras[idFrom].Stacks)
	end
	if idTo > 120 then
		PowaGlobalSet[idTo] = self.Auras[idTo]
	end
	if isMove then
		self:DeleteAura(self.Auras[idFrom])
		self:TriageIcones(self.CurrentAuraPage)
	end
	PowaMisc.GroupSize = 1
	self:CalculateAuraSequence()
	self:UpdateMainOption()
end

function PowaAurasOptions:MainOptionShow()
	if PowaOptionsFrame:IsVisible() then
		self:MainOptionClose()
	else
		if not aura then
			PowaSelected:Hide()
		end
		self:OptionHideAll()
		self.ModTest = true
		self:UpdateMainOption()
		PowaOptionsFrame:Show()
		PowaAurasOptions:UpdateMainOption(true)
		PlaySound("TalentScreenOpen", PowaMisc.SoundChannel)
		if PowaMisc.Disabled then
			self:DisplayText("Power Auras: "..self.Colors.Red..PowaAurasOptions.Text.Disabled.."|r")
		end
	end
end

function PowaAurasOptions:MainOptionClose()
	self:DisableMoveMode()
	self.ModTest = false
	if ColorPickerFrame:IsVisible() then
		self.CancelColor()
		ColorPickerFrame:Hide()
	end
	FontSelectorFrame:Hide()
	PowaBarConfigFrame:Hide()
	PowaOptionsFrame:Hide()
	PlaySound("TalentScreenClose", PowaMisc.SoundChannel)
	PowaAurasOptions:OptionHideAll()
	self:FindAllChildren()
	self:CreateEffectLists()
	self.DoCheck.All = true
	self:NewCheckBuffs()
	self:MemorizeActions()
	self:ReregisterEvents()
end

-- Main Options
function PowaAurasOptions:UpdateTimerOptions()
	local aura = self.Auras[self.CurrentAuraId]
	if not aura then
		return
	end
	if not aura.Timer then
		aura.Timer = cPowaTimer(aura)
	end
	local timer = aura.Timer
	if timer then
		PowaShowTimerButton:SetChecked(timer.enabled)
		PowaTimerAlphaSlider:SetValue(timer.a)
		PowaTimerSizeSlider:SetValue(timer.h)
		-- Timer Postion X Slider
		PowaTimerCoordXSlider:SetMinMaxValues(format("%.0f", timer.x - 10000), format("%.0f", timer.x + 10000))
		PowaTimerCoordXSliderLow:SetText(format("%.0f", timer.x - 700))
		PowaTimerCoordXSliderHigh:SetText(format("%.0f", timer.x + 700))
		PowaTimerCoordXSlider:SetValue(format("%.0f", timer.x))
		PowaTimerCoordXSlider:SetMinMaxValues(format("%.0f", timer.x - 700), format("%.0f", timer.x + 700))
		-- Timer Postion Y Slider
		PowaTimerCoordYSlider:SetMinMaxValues(format("%.0f", timer.y - 10000), format("%.0f", timer.y + 10000))
		PowaTimerCoordYSliderLow:SetText(format("%.0f", timer.y - 400))
		PowaTimerCoordYSliderHigh:SetText(format("%.0f", timer.y + 400))
		PowaTimerCoordYSlider:SetValue(format("%.0f", timer.y))
		PowaTimerCoordYSlider:SetMinMaxValues(format("%.0f", timer.y - 400), format("%.0f", timer.y + 400))
		PowaBuffTimerCentsButton:SetChecked(timer.cents)
		PowaBuffTimerLeadingZerosButton:SetChecked(timer.HideLeadingZeros)
		PowaBuffTimerTransparentButton:SetChecked(timer.Transparent)
		if aura:FullTimerAllowed() then
			-- Show full timer options
			PowaBuffTimerUpdatePingButton:SetChecked(timer.UpdatePing)
			self:EnableCheckBox("PowaBuffTimerUpdatePingButton")
			PowaBuffTimerActivationTime:Enable()
		else
			-- Show cut-down timer options
			PowaBuffTimerUpdatePingButton:SetChecked(false)
			self:DisableCheckBox("PowaBuffTimerUpdatePingButton")
			timer.ShowActivation = true
			PowaBuffTimerActivationTime:Disable()
		end
		PowaBuffTimerActivationTime:SetChecked(timer.ShowActivation)
		PowaBuffTimer99:SetChecked(timer.Seconds99)
		PowaBuffTimerUseOwnColorButton:SetChecked(timer.UseOwnColor)
		PowaTimerColorNormalTexture:SetVertexColor(timer.r, timer.g, timer.b)
		--UIDropDownMenu_SetSelectedValue(PowaBuffTimerRelative, timer.Relative)
		--UIDropDownMenu_SetSelectedValue(PowaDropDownTimerTexture, timer.Texture)
		PowaTimerInvertAuraSlider:SetValue(aura.InvertAuraBelow)
	end
end

function PowaAurasOptions:UpdateStacksOptions()
	local stacks = self.Auras[self.CurrentAuraId].Stacks
	if not stacks then
		return
	end
	PowaShowStacksButton:SetChecked(stacks.enabled)
	PowaStacksAlphaSlider:SetValue(stacks.a)
	PowaStacksSizeSlider:SetValue(stacks.h)
	-- Stacks Postion X Slider
	PowaStacksCoordXSlider:SetMinMaxValues(format("%.0f", stacks.x - 10000), format("%.0f", stacks.x + 10000))
	PowaStacksCoordXSliderLow:SetText(format("%.0f", stacks.x - 700))
	PowaStacksCoordXSliderHigh:SetText(format("%.0f", stacks.x + 700))
	PowaStacksCoordXSlider:SetValue(stacks.x)
	PowaStacksCoordXSlider:SetMinMaxValues(format("%.0f", stacks.x - 700), format("%.0f", stacks.x + 700))
	-- Stacks Postion Y Slider
	PowaStacksCoordYSlider:SetMinMaxValues(format("%.0f", stacks.y - 10000), format("%.0f", stacks.y + 10000))
	PowaStacksCoordYSliderLow:SetText(format("%.0f", stacks.y - 400))
	PowaStacksCoordYSliderHigh:SetText(format("%.0f", stacks.y + 400))
	PowaStacksCoordYSlider:SetValue(format("%.0f", stacks.y))
	PowaStacksCoordYSlider:SetMinMaxValues(format("%.0f", stacks.y - 400), format("%.0f", stacks.y + 400))
	PowaBuffStacksTransparentButton:SetChecked(stacks.Transparent)
	PowaBuffStacksUpdatePingButton:SetChecked(stacks.UpdatePing)
	PowaBuffStacksLegacySizing:SetChecked(stacks.LegacySizing)
	PowaBuffStacksUseOwnColorButton:SetChecked(stacks.UseOwnColor)
	PowaStacksColorNormalTexture:SetVertexColor(stacks.r, stacks.g, stacks.b)
	--UIDropDownMenu_SetSelectedValue(PowaBuffStacksRelative, stacks.Relative)
	--UIDropDownMenu_SetSelectedValue(PowaDropDownStacksTexture, stacks.Texture)
end

function PowaAurasOptions:SetOptionText(aura)
	PowaDropDownBuffTypeText:SetText(aura.OptionText.typeText)
	PowaRoundIconsButtonText:SetTextColor(0.5, 0.8, 0.9)
	if aura.OptionText.buffNameTooltip then
		PowaBarBuffName:Show()
		PowaBarBuffName.aide = aura.OptionText.buffNameTooltip
	else
		self:DisableTextfield("PowaBarBuffName")
	end
	if aura.OptionText.exactTooltip then
		self:EnableCheckBox("PowaExactButton")
		PowaExactButton.aide = aura.OptionText.exactTooltip
	else
		self:DisableCheckBox("PowaExactButton")
	end
	if aura.OptionText.mineText then
		self:EnableCheckBox("PowaMineButton")
		PowaMineButtonText:SetText(aura.OptionText.mineText)
		PowaMineButton.tooltipText = aura.OptionText.mineTooltip
	else
		PowaMineButton:SetChecked(false)
		self:DisableCheckBox("PowaMineButton")
	end
	if aura.OptionText.extraText then
		self:ShowCheckBox("PowaExtraButton")
		PowaExtraButtonText:SetText(aura.OptionText.extraText)
		PowaExtraButton.tooltipText = aura.OptionText.extraTooltip
	else
		PowaExtraButton:SetChecked(false)
		self:HideCheckBox("PowaExtraButton")
	end
	if aura.OptionText.targetFriendText then
		self:EnableCheckBox("PowaTargetFriendButton")
		PowaTargetFriendButtonText:SetText(aura.OptionText.targetFriendText)
		PowaTargetFriendButtonText:SetTextColor(0.2, 1.0, 0.2)
		PowaTargetFriendButton.tooltipText = aura.OptionText.targetFriendTooltip
	else
		PowaTargetFriendButton:SetChecked(false)
		self:DisableCheckBox("PowaTargetFriendButton")
	end
end

function PowaAurasOptions:ShowOptions(optionsToShow)
	for i = 1, #self.OptionHideables do
		local v = self.OptionHideables[i]
		if optionsToShow and optionsToShow[v] then
			_G[v]:Show()
		else
			_G[v]:Hide()
		end
	end
end

function PowaAurasOptions:EnableCheckBoxes(checkBoxesToEnable)
	for i = 1, #self.OptionCheckBoxes do
		local v = self.OptionCheckBoxes[i]
		if checkBoxesToEnable and checkBoxesToEnable[v] then
			self:EnableCheckBox(v, self.SetColors[v])
		else
			_G[v]:SetChecked(false)
			self:DisableCheckBox(v)
		end
	end
end

function PowaAurasOptions:EnableTernary(ternariesToEnable)
	for i = 1, #self.OptionTernary do
		local v = self.OptionTernary[i]
		if not ternariesToEnable or not ternariesToEnable[v] then
			self:DisableTernary(_G[v])
		end
	end
end

function PowaAurasOptions:SetupOptionsForAuraType(aura)
	self:SetOptionText(aura)
	self:ShowOptions(aura.ShowOptions)
	self:EnableCheckBoxes(aura.CheckBoxes)
	self:EnableTernary(aura.Ternary)
	if aura:ShowTimerDurationSlider() then
		PowaTimerDurationSlider:Show()
	else
		PowaTimerDurationSlider:Hide()
	end
	if aura.CanHaveInvertTime then
		PowaTimerInvertAuraSlider:Show()
	else
		PowaTimerInvertAuraSlider:Hide()
	end
end

function PowaAurasOptions:InitPage(aura)
	if not aura then
		aura = self.Auras[self.CurrentAuraId]
	end
	if PowaMisc.GroupSize > 1 then
		PowaAurasOptions:IconOnMouseWheel(nil)
	end
	PowaAurasOptions:InitalizeOnMenuOpen()
	self:UpdateTimerOptions()
	UIDropDownMenu_SetSelectedName(PowaStrataDropDown, aura.strata)
	UIDropDownMenu_SetSelectedName(PowaTextureStrataDropDown, aura.texturestrata)
	UIDropDownMenu_SetSelectedName(PowaBlendModeDropDown, aura.blendmode)
	UIDropDownMenu_SetSelectedName(PowaSecondaryBlendModeDropDown, aura.secondaryblendmode)
	UIDropDownMenu_SetSelectedName(PowaSecondaryStrataDropDown, aura.secondarystrata)
	UIDropDownMenu_SetSelectedName(PowaSecondaryTextureStrataDropDown, aura.secondarytexturestrata)
	UIDropDownMenu_SetSelectedName(PowaGradientStyleDropDown, aura.gradientstyle)
	PowaFrameStrataLevelSlider:SetValue(aura.stratalevel)
	PowaTextureStrataSublevelSlider:SetValue(aura.texturesublevel)
	PowaStrataDropDownText:SetText(aura.strata)
	PowaTextureStrataDropDownText:SetText(aura.texturestrata)
	PowaBlendModeDropDownText:SetText(aura.blendmode)
	PowaSecondaryBlendModeDropDownText:SetText(aura.secondaryblendmode)
	PowaSecondaryStrataDropDownText:SetText(aura.secondarystrata)
	PowaSecondaryTextureStrataDropDownText:SetText(aura.secondarytexturestrata)
	PowaGradientStyleDropDownText:SetText(aura.gradientstyle)
	PowaDropDownAnim1Text:SetText(self.Anim[aura.anim1])
	PowaDropDownAnim2Text:SetText(self.Anim[aura.anim2])
	PowaDropDownAnimBeginText:SetText(self.BeginAnimDisplay[aura.begin])
	PowaDropDownAnimEndText:SetText(self.EndAnimDisplay[aura.finish])
	if aura.sound < 30 then
		PowaDropDownSoundText:SetText(self.Sound[aura.sound])
		PowaDropDownSound2Text:SetText(self.Sound[30])
	else
		PowaDropDownSoundText:SetText(self.Sound[0])
		PowaDropDownSound2Text:SetText(self.Sound[aura.sound])
	end
	if aura.soundend < 30 then
		PowaDropDownSoundEndText:SetText(self.Sound[aura.soundend])
		PowaDropDownSound2EndText:SetText(self.Sound[30])
	else
		PowaDropDownSoundEndText:SetText(self.Sound[0])
		PowaDropDownSound2EndText:SetText(self.Sound[aura.soundend])
	end
	PowaBarCustomSound.aide = self.Text.aideCustomSound
	PowaBarCustomSoundEnd.aide = self.Text.aideCustomSoundEnd
	PowaDropDownStanceText:SetText(self.PowaStance[aura.stance])
	PowaDropDownGTFOText:SetText(self.PowaGTFO[aura.GTFO])
	PowaBarBuffStacks.aide = self.Text.aideStacks
	PowaOwntexButton:SetChecked(aura.owntex)
	PowaRoundIconsButton:SetChecked(aura.roundicons)
	PowaWowTextureButton:SetChecked(aura.wowtex)
	PowaModelsButton:SetChecked(aura.model)
	PowaCustomModelsButton:SetChecked(aura.modelcustom)
	PowaCustomTextureButton:SetChecked(aura.customtex)
	PowaTextAuraButton:SetChecked(aura.textaura)
	PowaRandomColorButton:SetChecked(aura.randomcolor)
	PowaShowSpinAtBeginning:SetChecked(aura.beginSpin)
	PowaOldAnimation:SetChecked(aura.UseOldAnimations)
	if PowaOldAnimation:GetChecked() == true then
		PowaShowSpinAtBeginning:Hide()
	else
		PowaShowSpinAtBeginning:Show()
	end
	PowaIngoreCaseButton:SetChecked(aura.ignoremaj)
	PowaInverseButton:SetChecked(aura.inverse)
	PowaTargetButton:SetChecked(aura.target)
	PowaTargetFriendButton:SetChecked(aura.targetfriend)
	PowaPartyButton:SetChecked(aura.party)
	PowaFocusButton:SetChecked(aura.focus)
	PowaRaidButton:SetChecked(aura.raid)
	PowaGroupOrSelfButton:SetChecked(aura.groupOrSelf)
	PowaGroupAnyButton:SetChecked(aura.groupany)
	PowaOptunitnButton:SetChecked(aura.optunitn)
	PowaExactButton:SetChecked(aura.exact)
	PowaMineButton:SetChecked(aura.mine)
	PowaThresholdInvertButton:SetChecked(aura.thresholdinvert)
	PowaExtraButton:SetChecked(aura.Extra)
	PowaDesaturateButton:SetChecked(aura.desaturation)
	PowaEnableFullRotationButton:SetChecked(aura.enablefullrotation)
	-- Ternary Logic
	self:TernarySetState(PowaInCombatButton, aura.combat)
	self:TernarySetState(PowaIsInRaidButton, aura.inRaid)
	self:TernarySetState(PowaIsInPartyButton, aura.inParty)
	self:TernarySetState(PowaRestingButton, aura.isResting)
	self:TernarySetState(PowaIsMountedButton, aura.ismounted)
	self:TernarySetState(PowaInVehicleButton, aura.inVehicle)
	self:TernarySetState(PowaInPetBattleButton, aura.inPetBattle)
	self:TernarySetState(PowaIsAliveButton, aura.isAlive)
	self:TernarySetState(PowaPvPButton, aura.PvP)
	self:TernarySetState(PowaScenarioInstanceButton, aura.InstanceScenario)
	self:TernarySetState(PowaScenarioHeroicInstanceButton, aura.InstanceScenarioHeroic)
	self:TernarySetState(Powa5ManInstanceButton, aura.Instance5Man)
	self:TernarySetState(Powa5ManHeroicInstanceButton, aura.Instance5ManHeroic)
	self:TernarySetState(PowaChallangeModeInstanceButton, aura.InstanceChallengeMode)
	self:TernarySetState(Powa10ManInstanceButton, aura.Instance10Man)
	self:TernarySetState(Powa10ManHeroicInstanceButton, aura.Instance10ManHeroic)
	self:TernarySetState(Powa25ManInstanceButton, aura.Instance25Man)
	self:TernarySetState(Powa25ManHeroicInstanceButton, aura.Instance25ManHeroic)
	self:TernarySetState(PowaRoleTankButton, aura.RoleTank)
	self:TernarySetState(PowaRoleHealerButton, aura.RoleHealer)
	self:TernarySetState(PowaRoleMeleDpsButton, aura.RoleMeleDps)
	self:TernarySetState(PowaRoleRangeDpsButton, aura.RoleRangeDps)
	self:TernarySetState(PowaBgInstanceButton, aura.InstanceBg)
	self:TernarySetState(PowaArenaInstanceButton, aura.InstanceArena)
	PowaTimerDurationSlider:SetValue(aura.timerduration)
	self:SetThresholdSlider(aura)
	-- Dual specs
	self:EnableCheckBox("PowaTalentGroup1Button")
	self:EnableCheckBox("PowaTalentGroup2Button")
	PowaTalentGroup1Button:SetChecked(aura.spec1)
	PowaTalentGroup2Button:SetChecked(aura.spec2)
	self:EnableCheckBox("PowaAuraDebugButton")
	PowaAuraDebugButton:SetChecked(aura.Debug)
	aura:HideShowTabs()
	self:SetupOptionsForAuraType(aura)
	-- Page changes
	if PowaBarConfigFrameEditor4:IsVisible() and not PowaEditorTab4:IsVisible() then
		PanelTemplates_SelectTab(PowaEditorTab1)
		PanelTemplates_DeselectTab(PowaEditorTab2)
		PanelTemplates_DeselectTab(PowaEditorTab4)
		PowaBarConfigFrameEditor1:Show()
		PowaBarConfigFrameEditor2:Hide()
		PowaBarConfigFrameEditor4:Hide()
	end
	-- Auras visuals
	PowaBarAuraAlphaSlider:SetValue(format("%.0f", aura.alpha * 100))
	PowaBarAuraRotateSlider:SetValue(format("%.0f", aura.rotate))
	if aura.enablefullrotation then
		PowaBarAuraRotateSlider:SetValueStep(1)
	else
		PowaBarAuraRotateSlider:SetValueStep(90)
	end
	-- Model Position Z Slider
	PowaModelPositionZSlider:SetMinMaxValues(format("%.0f", (aura.mz * 100) - 10000), format("%.0f", (aura.mz * 100) + 10000))
	PowaModelPositionZSliderLow:SetText(format("%.0f", (aura.mz * 100) - 100))
	PowaModelPositionZSliderHigh:SetText(format("%.0f", (aura.mz * 100) + 100))
	PowaModelPositionZSlider:SetValue(format("%.0f", aura.mz * 100))
	PowaModelPositionZSlider:SetMinMaxValues(format("%.0f", (aura.mz * 100) - 100), format("%.0f", (aura.mz * 100) + 100))
	-- Model Position X Slider
	PowaModelPositionXSlider:SetMinMaxValues(format("%.0f", (aura.mx * 100) - 10000), format("%.0f", (aura.mx * 100) + 10000))
	PowaModelPositionXSliderLow:SetText(format("%.0f", (aura.mx * 100) - 50))
	PowaModelPositionXSliderHigh:SetText(format("%.0f", (aura.mx * 100) + 50))
	PowaModelPositionXSlider:SetValue(format("%.0f", aura.mx * 100))
	PowaModelPositionXSlider:SetMinMaxValues(format("%.0f", (aura.mx * 100) - 50), format("%.0f", (aura.mx * 100) + 50))
	-- Model Position Y Slider
	PowaModelPositionYSlider:SetMinMaxValues(format("%.0f", (aura.my * 100) - 10000), format("%.0f", (aura.my * 100) + 10000))
	PowaModelPositionYSliderLow:SetText(format("%.0f", (aura.my * 100) - 50))
	PowaModelPositionYSliderHigh:SetText(format("%.0f", (aura.my * 100) + 50))
	PowaModelPositionYSlider:SetValue(format("%.0f", aura.my * 100))
	PowaModelPositionYSlider:SetMinMaxValues(format("%.0f", (aura.my * 100) - 50), format("%.0f", (aura.my * 100) + 50))
	-- Texture Size Slider
	PowaBarAuraSizeSlider:SetMinMaxValues(1, format("%.0f", (aura.size * 100) + 10000))
	PowaBarAuraSizeSliderLow:SetText("1%")
	PowaBarAuraSizeSliderHigh:SetText(format("%.0f", ((aura.size * 100) + 100)).."%")
	PowaBarAuraSizeSlider:SetValue(format("%.0f", aura.size * 100))
	PowaBarAuraSizeSlider:SetMinMaxValues(1, format("%.0f", (aura.size * 100) + 100))
	-- Texture Position X Slider
	PowaBarAuraCoordXSlider:SetMinMaxValues(format("%.0f", aura.x - 10000), format("%.0f", aura.x + 10000))
	PowaBarAuraCoordXSliderLow:SetText(format("%.0f", aura.x - 700))
	PowaBarAuraCoordXSliderHigh:SetText(format("%.0f", aura.x + 700))
	PowaBarAuraCoordXSlider:SetValue(format("%.0f", aura.x))
	PowaBarAuraCoordXSlider:SetMinMaxValues(format("%.0f", aura.x - 700), format("%.0f", aura.x + 700))
	-- Texture Position Y Slider
	PowaBarAuraCoordYSlider:SetMinMaxValues(format("%.0f", aura.y - 10000), format("%.0f", aura.y + 10000))
	PowaBarAuraCoordYSliderLow:SetText(format("%.0f", aura.y - 400))
	PowaBarAuraCoordYSliderHigh:SetText(format("%.0f", aura.y + 400))
	PowaBarAuraCoordYSlider:SetValue(format("%.0f", aura.y))
	PowaBarAuraCoordYSlider:SetMinMaxValues(format("%.0f", aura.y - 400), format("%.0f", aura.y + 400))
	PowaBarAuraAnimSpeedSlider:SetValue(format("%.0f", aura.speed * 100))
	PowaBarAuraDurationSlider:SetValue(format("%.2f", aura.duration))
	PowaBarAuraSymSlider:SetValue(format("%.0f", aura.symetrie))
	PowaBarAnimationSlider:SetValue(format("%.0f", aura.modelanimation))
	PowaBarAuraDeformSlider:SetValue(format("%.2f", aura.torsion))
	PowaBarBuffName:SetText(aura.buffname)
	PowaBarMultiID:SetText(aura.multiids)
	PowaBarTooltipCheck:SetText(aura.tooltipCheck)
	PowaBarCustomSound:SetText(aura.customsound)
	PowaBarCustomSoundEnd:SetText(aura.customsoundend)
	PowaBarUnitn:SetText(aura.unitn)
	PowaBarBuffStacks:SetText(aura:StacksText())
	PowaAurasOptions:UpdateStacksOptions()
	PowaAurasOptions:UpdateTimerOptions()
	if aura.optunitn then
		self:EnableTextfield("PowaBarUnitn")
	elseif aura.optunitn == false then
		self:DisableTextfield("PowaBarUnitn")
	end
	if not aura.icon or aura.icon == "" then
		PowaIconTexture:SetTexture("Interface\\Icons\\Inv_Misc_QuestionMark")
	else
		PowaIconTexture:SetTexture(aura.icon)
	end
	local checkTexture = 0
	if aura.owntex then
		checkTexture = AuraTexture:SetTexture(PowaIconTexture:GetTexture())
		PowaBlendModeDropDown:Show()
		PowaTextureStrataDropDown:Show()
		PowaTextureStrataSublevelSlider:Show()
		PowaBarAuraSymSlider:Show()
		PowaModelPositionZSlider:Hide()
		PowaModelPositionXSlider:Hide()
		PowaModelPositionYSlider:Hide()
		PowaBarCustomTexName:Hide()
		PowaBarCustomModelsEditBox:Hide()
		PowaBarAurasText:Hide()
		PowaFontButton:Hide()
		PowaBarAnimationSlider:Hide()
	elseif aura.wowtex then
		PowaBarAuraTextureSlider:Show()
		PowaBlendModeDropDown:Show()
		PowaTextureStrataDropDown:Show()
		PowaTextureStrataSublevelSlider:Show()
		PowaBarAuraSymSlider:Show()
		PowaModelPositionZSlider:Hide()
		PowaModelPositionXSlider:Hide()
		PowaModelPositionYSlider:Hide()
		PowaBarCustomTexName:Hide()
		PowaBarCustomModelsEditBox:Hide()
		PowaBarAurasText:Hide()
		PowaFontButton:Hide()
		PowaBarAnimationSlider:Hide()
		if (#self.WowTextures > self.MaxTextures) or (#self.WowTextures > #PowaAurasModels) then
			PowaBarAuraTextureSlider:SetMinMaxValues(1, #self.WowTextures)
			PowaBarAuraTextureSlider:SetValue(aura.texture)
		else
			PowaBarAuraTextureSlider:SetValue(aura.texture)
			PowaBarAuraTextureSlider:SetMinMaxValues(1, #self.WowTextures)
		end
		PowaBarAuraTextureSliderHigh:SetText(#self.WowTextures)
		checkTexture = AuraTexture:SetTexture(self.WowTextures[aura.texture])
	elseif aura.model then
		PowaModelPositionZSlider:Show()
		PowaModelPositionXSlider:Show()
		PowaModelPositionYSlider:Show()
		PowaBarAuraTextureSlider:Show()
		PowaBarAnimationSlider:Show()
		PowaBlendModeDropDown:Hide()
		PowaTextureStrataDropDown:Hide()
		PowaTextureStrataSublevelSlider:Hide()
		PowaBarCustomTexName:Hide()
		PowaBarAurasText:Hide()
		PowaFontButton:Hide()
		PowaBarCustomModelsEditBox:Hide()
		PowaBarAuraSymSlider:Hide()
		if (#PowaAurasModels > self.MaxTextures) or (#PowaAurasModels > #self.WowTextures) then
			PowaBarAuraTextureSlider:SetMinMaxValues(1, #PowaAurasModels)
			PowaBarAuraTextureSlider:SetValue(aura.texture)
		else
			PowaBarAuraTextureSlider:SetValue(aura.texture)
			PowaBarAuraTextureSlider:SetMinMaxValues(1, #PowaAurasModels)
		end
		PowaBarAuraTextureSliderHigh:SetText(#PowaAurasModels)
		checkTexture = AuraTexture:SetTexture("Interface\\Icons\\TEMP")
	elseif aura.modelcustom then
		PowaModelPositionZSlider:Show()
		PowaModelPositionXSlider:Show()
		PowaModelPositionYSlider:Show()
		PowaBarAuraTextureSlider:Show()
		PowaBarAnimationSlider:Show()
		PowaBarCustomModelsEditBox:SetText(aura.modelcustompath)
		PowaBlendModeDropDown:Hide()
		PowaTextureStrataDropDown:Hide()
		PowaTextureStrataSublevelSlider:Hide()
		PowaBarCustomTexName:Hide()
		PowaBarAuraTextureSlider:Hide()
		PowaBarCustomModelsEditBox:Show()
		PowaBarAurasText:Hide()
		PowaFontButton:Hide()
		PowaBarAuraSymSlider:Hide()
		checkTexture = AuraTexture:SetTexture("Interface\\Icons\\TEMP")
	elseif aura.customtex then
		PowaBarAuraTextureSlider:Hide()
		PowaBlendModeDropDown:Show()
		PowaTextureStrataDropDown:Show()
		PowaTextureStrataSublevelSlider:Show()
		PowaBarAuraSymSlider:Show()
		PowaModelPositionZSlider:Hide()
		PowaModelPositionXSlider:Hide()
		PowaModelPositionYSlider:Hide()
		PowaBarAurasText:Hide()
		PowaBarCustomModelsEditBox:Hide()
		PowaFontButton:Hide()
		PowaBarCustomTexName:Show()
		PowaBarCustomTexName:SetText(aura.customname)
		PowaBarAnimationSlider:Hide()
		checkTexture = AuraTexture:SetTexture(self:CustomTexPath(aura.customname))
	elseif aura.textaura then
		PowaBarAuraTextureSlider:Hide()
		PowaBlendModeDropDown:Show()
		PowaTextureStrataDropDown:Show()
		PowaTextureStrataSublevelSlider:Show()
		PowaBarAuraSymSlider:Show()
		PowaModelPositionZSlider:Hide()
		PowaModelPositionXSlider:Hide()
		PowaModelPositionYSlider:Hide()
		PowaBarCustomTexName:Hide()
		PowaBarCustomModelsEditBox:Hide()
		PowaBarAurasText:Show()
		PowaFontButton:Show()
		PowaBarAurasText:SetText(aura.aurastext)
		PowaBarAnimationSlider:Hide()
		checkTexture = AuraTexture:SetTexture("Interface\\Icons\\INV_Scroll_02")
	else
		PowaBarAuraTextureSlider:Show()
		PowaBlendModeDropDown:Show()
		PowaTextureStrataDropDown:Show()
		PowaTextureStrataSublevelSlider:Show()
		PowaBarAuraSymSlider:Show()
		PowaModelPositionZSlider:Hide()
		PowaModelPositionXSlider:Hide()
		PowaModelPositionYSlider:Hide()
		PowaBarCustomTexName:Hide()
		PowaBarCustomModelsEditBox:Hide()
		PowaBarAurasText:Hide()
		PowaFontButton:Hide()
		PowaBarAnimationSlider:Hide()
		if (#self.WowTextures < self.MaxTextures) or (#PowaAurasModels < #self.MaxTextures) then
			PowaBarAuraTextureSlider:SetMinMaxValues(1, self.MaxTextures)
			PowaBarAuraTextureSlider:SetValue(aura.texture)
		else
			PowaBarAuraTextureSlider:SetValue(aura.texture)
			PowaBarAuraTextureSlider:SetMinMaxValues(1, self.MaxTextures)
		end
		PowaBarAuraTextureSliderHigh:SetText(self.MaxTextures)
		checkTexture = AuraTexture:SetTexture("Interface\\Addons\\PowerAuras\\Auras\\Aura"..aura.texture..".tga")
	end
	if checkTexture ~= 1 then
		AuraTexture:SetTexture("Interface\\CharacterFrame\\TempPortrait.tga")
	end
	if aura.gradientstyle == "Horizontal" or aura.gradientstyle == "Vertical" then
		AuraTexture:SetGradientAlpha(aura.gradientstyle, aura.r, aura.g, aura.b, 1.0, aura.gr, aura.gg, aura.gb, 1.0)
	else
		AuraTexture:SetVertexColor(aura.r, aura.g, aura.b)
	end
	if AuraTexture:GetTexture() == "Interface\\CharacterFrame\\TempPortrait" or AuraTexture:GetTexture() == "Interface\\Icons\\INV_Scroll_02" or AuraTexture:GetTexture() == "Interface\\Icons\\TEMP" then
		AuraTexture:SetVertexColor(1, 1, 1)
	end
	PowaColorNormalTexture:SetVertexColor(aura.r, aura.g, aura.b)
	PowaGradientColorNormalTexture:SetVertexColor(aura.gr, aura.gg, aura.gb)
	PowaColor_SwatchBg.r = aura.r
	PowaColor_SwatchBg.g = aura.g
	PowaColor_SwatchBg.b = aura.b
	PowaGradientColor_SwatchBg.r = aura.gr
	PowaGradientColor_SwatchBg.g = aura.gg
	PowaGradientColor_SwatchBg.b = aura.gb
	if PowaMisc.GroupSize == 1 then
		PowaHeader:SetText(self.Text.nomEffectEditor.." ("..aura.id..")")
	else
		PowaHeader:SetText(self.Text.nomEffectEditor.." ("..aura.id.." - "..aura.id + (PowaMisc.GroupSize - 1)..")")
	end
end

function PowaAurasOptions:SetThresholdSlider(aura)
	if not aura.MaxRange then
		return
	end
	PowaBarThresholdSlider:SetMinMaxValues(0, aura.MaxRange)
	PowaBarThresholdSlider:SetValue(aura.threshold)
	PowaBarThresholdSliderLow:SetText("0"..aura.RangeType)
	PowaBarThresholdSliderHigh:SetText(aura.MaxRange..aura.RangeType)
	self.SliderEditBoxChanged(PowaBarThresholdSliderEditBox)
end

-- Sliders Changed
function PowaAurasOptions:BarAuraTextureSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if value == 0 or not value then
		SliderValue = 1
		self:SetValue(value)
	end
	local checkTexture = 0
	local aura = self.Auras[self.CurrentAuraId]
	if aura.owntex then
		checkTexture = AuraTexture:SetTexture(aura.icon)
	elseif aura.wowtex then
		checkTexture = AuraTexture:SetTexture(self.WowTextures[value])
	elseif aura.model then
		checkTexture = AuraTexture:SetTexture("Interface\\Icons\\TEMP")
	elseif aura.modelcustom then
		checkTexture = AuraTexture:SetTexture("Interface\\Icons\\TEMP")
	elseif aura.customtex then
		checkTexture = AuraTexture:SetTexture(self:CustomTexPath(aura.customname))
	elseif aura.textaura then
		checkTexture = AuraTexture:SetTexture("Interface\\Icons\\INV_Scroll_02")
	else
		checkTexture = AuraTexture:SetTexture("Interface\\Addons\\PowerAuras\\Auras\\Aura"..value..".tga")
	end
	if checkTexture ~= 1 then
		AuraTexture:SetTexture("Interface\\CharacterFrame\\TempPortrait.tga")
	end
	local aura = self.Auras[self.CurrentAuraId]
	if aura.textaura or AuraTexture:GetTexture() == "Interface\\CharacterFrame\\TempPortrait" or AuraTexture:GetTexture() == "Interface\\Icons\\TEMP" then
		AuraTexture:SetVertexColor(1, 1, 1)
	else
		if aura.gradientstyle == "Horizontal" or aura.gradientstyle == "Vertical" then
			AuraTexture:SetGradientAlpha(aura.gradientstyle, aura.r, aura.g, aura.b, 1.0, aura.gr, aura.gg, aura.gb, 1.0)
		else
			AuraTexture:SetVertexColor(aura.r, aura.g, aura.b)
		end
	end
	if value ~= aura.texture then
		aura.texture = value
		self:RedisplayAura(self.CurrentAuraId)
	end
end

function PowaAurasOptions:FrameStrataLevelSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if value ~= self.Auras[self.CurrentAuraId].stratalevel then
		self.Auras[self.CurrentAuraId].stratalevel = value
		self:RedisplayAura(self.CurrentAuraId)
	end
end

function PowaAurasOptions:TextureStrataSublevelSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if value ~= self.Auras[self.CurrentAuraId].texturesublevel then
		self.Auras[self.CurrentAuraId].texturesublevel = value
		self:RedisplayAura(self.CurrentAuraId)
	end
end

function PowaAurasOptions:ModelPositionZSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if value / 100 ~= self.Auras[self.CurrentAuraId].mz then
		self.Auras[self.CurrentAuraId].mz = value / 100
		self:RedisplayAura(self.CurrentAuraId)
	end
end

function PowaAurasOptions:ModelPositionXSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if value / 100 ~= self.Auras[self.CurrentAuraId].mx then
		self.Auras[self.CurrentAuraId].mx = value / 100
		self:RedisplayAura(self.CurrentAuraId)
	end
end

function PowaAurasOptions:ModelPositionYSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if value / 100 ~= self.Auras[self.CurrentAuraId].my then
		self.Auras[self.CurrentAuraId].my = value / 100
		self:RedisplayAura(self.CurrentAuraId)
	end
end

function PowaAurasOptions:BarAuraAlphaSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if PowaMisc.GroupSize == 1 then
		if value / 100 ~= self.Auras[self.CurrentAuraId].alpha then
			self.Auras[self.CurrentAuraId].alpha = value / 100
			self:RedisplayAura(self.CurrentAuraId)
		end
	else
		if value / 100 ~= self.Auras[self.CurrentAuraId].alpha then
			local min = self.CurrentAuraId
			local max = min + (PowaMisc.GroupSize - 1)
			local relativepos = { }
			for i = min, max do
				if self.Auras[i] ~= nil then
					relativepos[i] = self.Auras[i].alpha
				end
			end
			for i = min, max do
				if self.Auras[i] ~= nil then
					if i == min then
						self.Auras[i].alpha = value / 100
					else
						if relativepos[min] < relativepos[i] then
							self.Auras[i].alpha = (value / 100) + (relativepos[i] - relativepos[min])
						else
							self.Auras[i].alpha = (value / 100) + (relativepos[min] - relativepos[i])
						end
					end
					self:RedisplayAura(i)
				end
			end
			PowaAurasOptions:UpdatePreviewColor(self.Auras[self.CurrentAuraId])
		end
	end
end

function PowaAurasOptions:BarAuraSizeSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	local aura = self.Auras[self.CurrentAuraId]
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if aura.textaura then
		if PowaMisc.GroupSize == 1 then
			if value / 100 ~= self.Auras[self.CurrentAuraId].size then
				if (value / 100) < 1.61 then
					self.Auras[self.CurrentAuraId].size = value / 100
					self:RedisplayAura(self.CurrentAuraId)
				end
			end
		else
			if value / 100 ~= self.Auras[self.CurrentAuraId].size then
				local min = self.CurrentAuraId
				local max = min + (PowaMisc.GroupSize - 1)
				local relativepos = { }
				for i = min, max do
					if self.Auras[i] ~= nil then
						relativepos[i] = self.Auras[i].size
					end
				end
				for i = min, max do
					if self.Auras[i] ~= nil then
						if i == min then
							self.Auras[i].size = value / 100
						else
							if relativepos[min] < relativepos[i] then
								self.Auras[i].size = (value / 100) + (relativepos[i] - relativepos[min])
							else
								self.Auras[i].size = (value / 100) + (relativepos[min] - relativepos[i])
							end
						end
						self:RedisplayAura(i)
					end
				end
				PowaAurasOptions:UpdatePreviewColor(self.Auras[self.CurrentAuraId])
			end
		end
	else
		if PowaMisc.GroupSize == 1 then
			if value / 100 ~= self.Auras[self.CurrentAuraId].size then
				self.Auras[self.CurrentAuraId].size = value / 100
				self:RedisplayAura(self.CurrentAuraId)
			end
		else
			if value / 100 ~= self.Auras[self.CurrentAuraId].size then
				local min = self.CurrentAuraId
				local max = min + (PowaMisc.GroupSize - 1)
				local relativepos = { }
				for i = min, max do
					if self.Auras[i] ~= nil then
						relativepos[i] = self.Auras[i].size
					end
				end
				for i = min, max do
					if self.Auras[i] ~= nil then
						if i == min then
							self.Auras[i].size = value / 100
						else
							if relativepos[min] < relativepos[i] then
								self.Auras[i].size = (value / 100) + (relativepos[i] - relativepos[min])
							else
								self.Auras[i].size = (value / 100) + (relativepos[min] - relativepos[i])
							end
						end
						self:RedisplayAura(i)
					end
				end
				PowaAurasOptions:UpdatePreviewColor(self.Auras[self.CurrentAuraId])
			end
		end
	end
end

function PowaAurasOptions:BarAuraCoordXSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if PowaMisc.GroupSize == 1 then
		if value ~= self.Auras[self.CurrentAuraId].x then
			self.Auras[self.CurrentAuraId].x = value
			self:RedisplayAura(self.CurrentAuraId)
		end
	else
		if value ~= self.Auras[self.CurrentAuraId].x then
			local min = self.CurrentAuraId
			local max = min + (PowaMisc.GroupSize - 1)
			local relativepos = { }
			for i = min, max do
				if self.Auras[i] then
					relativepos[i] = self.Auras[i].x
				end
			end
			for i = min, max do
				if self.Auras[i] then
					if i == min then
						self.Auras[i].x = value
					else
						self.Auras[i].x = value + (relativepos[i] - relativepos[min])
					end
					self:RedisplayAura(i)
				end
			end
			PowaAurasOptions:UpdatePreviewColor(self.Auras[self.CurrentAuraId])
		end
	end
end

function PowaAurasOptions:BarAuraCoordYSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if PowaMisc.GroupSize == 1 then
		if value ~= self.Auras[self.CurrentAuraId].y then
			self.Auras[self.CurrentAuraId].y = value
			self:RedisplayAura(self.CurrentAuraId)
		end
	else
		if value ~= self.Auras[self.CurrentAuraId].y then
			local min = self.CurrentAuraId
			local max = min + (PowaMisc.GroupSize - 1)
			local relativepos = { }
			for i = min, max do
				if self.Auras[i] then
					relativepos[i] = self.Auras[i].y
				end
			end
			for i = min, max do
				if self.Auras[i] then
					if i == min then
						self.Auras[i].y = value
					else
						self.Auras[i].y = value + (relativepos[i] - relativepos[min])
					end
					self:RedisplayAura(i)
				end
			end
			PowaAurasOptions:UpdatePreviewColor(self.Auras[self.CurrentAuraId])
		end
	end
end

function PowaAurasOptions:SecondaryFrameStrataLevelSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if value ~= self.Auras[self.CurrentAuraId].secondarystratalevel then
		self.Auras[self.CurrentAuraId].secondarystratalevel = value
		self:RedisplayAura(self.CurrentAuraId)
	end
end

function PowaAurasOptions:SecondaryTextureStrataSublevelSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if value ~= self.Auras[self.CurrentAuraId].secondarytexturesublevel then
		self.Auras[self.CurrentAuraId].secondarytexturesublevel = value
		self:RedisplayAura(self.CurrentAuraId)
	end
end

function PowaAurasOptions:BarAuraAnimSpeedSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if value / 100 ~= self.Auras[self.CurrentAuraId].speed then
		self.Auras[self.CurrentAuraId].speed = value / 100
		self:RedisplayAura(self.CurrentAuraId)
	end
end

function PowaAurasOptions:BarAuraAnimDurationSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if value ~= self.Auras[self.CurrentAuraId].duration then
		self.Auras[self.CurrentAuraId].duration = value
		self:RedisplayAura(self.CurrentAuraId)
	end
end

function PowaAurasOptions:BarAuraSymSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if value == 0 then
		PowaBarAuraSymSliderText:SetText(self.Text.nomSymetrie..": "..self.Text.aucune)
		--AuraTexture:SetTexCoord(0, 1, 0, 1)
	elseif value == 1 then
		PowaBarAuraSymSliderText:SetText(self.Text.nomSymetrie..": X")
		--AuraTexture:SetTexCoord(1, 0, 0, 1)
	elseif value == 2 then
		PowaBarAuraSymSliderText:SetText(self.Text.nomSymetrie..": Y")
		--AuraTexture:SetTexCoord(0, 1, 1, 0)
	elseif value == 3 then
		PowaBarAuraSymSliderText:SetText(self.Text.nomSymetrie..": XY")
		--AuraTexture:SetTexCoord(1, 0, 1, 0)
	end
	if PowaMisc.GroupSize == 1 then
		if value ~= self.Auras[self.CurrentAuraId].symetrie then
			self.Auras[self.CurrentAuraId].symetrie = value
			self:RedisplayAura(self.CurrentAuraId)
		end
	else
		if value ~= self.Auras[self.CurrentAuraId].symetrie then
			local min = self.CurrentAuraId
			local max = min + (PowaMisc.GroupSize - 1)
			local relativepos = { }
			for i = min, max do
				if self.Auras[i] then
					relativepos[i] = self.Auras[i].symetrie
				end
			end
			for i = min, max do
				if self.Auras[i] then
					if i == min then
						self.Auras[i].symetrie = value
					else
						if relativepos[min] < relativepos[i] then
							self.Auras[i].symetrie = value + (relativepos[i] - relativepos[min])
						else
							self.Auras[i].symetrie = value + (relativepos[min] - relativepos[i])
						end
					end
					self:RedisplayAura(i)
				end
			end
			PowaAurasOptions:UpdatePreviewColor(self.Auras[self.CurrentAuraId])
		end
	end
end

function PowaAurasOptions:BarAnimationSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if value == - 1 then
		PowaBarAnimationSliderText:SetText("Animation: Default")
	else
		PowaBarAnimationSliderText:SetText("Animation: "..value)
	end
	if value ~= self.Auras[self.CurrentAuraId].modelanimation then
		self.Auras[self.CurrentAuraId].modelanimation = value
		self:RedisplayAura(self.CurrentAuraId)
	end
end

function PowaAurasOptions:BarAuraRotateSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	--[[if self.Auras[self.CurrentAuraId].textaura ~= true then
		AuraTexture:SetPoint("CENTER")
		AuraTexture:SetRotation(math.rad(value))
	end]]--
	if PowaMisc.GroupSize == 1 then
		if value ~= self.Auras[self.CurrentAuraId].rotate then
			self.Auras[self.CurrentAuraId].rotate = value
			self:RedisplayAura(self.CurrentAuraId)
		end
	else
		if value ~= self.Auras[self.CurrentAuraId].rotate then
			local min = self.CurrentAuraId
			local max = min + (PowaMisc.GroupSize - 1)
			local relativepos = { }
			for i = min, max do
				if self.Auras[i] then
					relativepos[i] = self.Auras[i].rotate
				end
			end
			for i = min, max do
				if self.Auras[i] then
					if i == min then
						self.Auras[i].rotate = value
					else
						if relativepos[min] < relativepos[i] then
							self.Auras[i].rotate = value + (relativepos[i] - relativepos[min])
						else
							self.Auras[i].rotate = value + (relativepos[min] - relativepos[i])
						end
					end
					self:RedisplayAura(i)
				end
			end
			PowaAurasOptions:UpdatePreviewColor(self.Auras[self.CurrentAuraId])
		end
	end
end

function PowaAurasOptions:BarAuraDeformSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if PowaMisc.GroupSize == 1 then
		if value ~= self.Auras[self.CurrentAuraId].torsion then
			self.Auras[self.CurrentAuraId].torsion = value
			self:RedisplayAura(self.CurrentAuraId)
		end
	else
		if value ~= self.Auras[self.CurrentAuraId].torsion then
			local min = self.CurrentAuraId
			local max = min + (PowaMisc.GroupSize - 1)
			local relativepos = { }
			for i = min, max do
				if self.Auras[i] then
					relativepos[i] = self.Auras[i].torsion
				end
			end
			for i = min, max do
				if self.Auras[i] then
					if i == min then
						self.Auras[i].torsion = value
					else
						if relativepos[min] < relativepos[i] then
							self.Auras[i].torsion = value + (relativepos[i] - relativepos[min])
						else
							self.Auras[i].torsion = value + (relativepos[min] - relativepos[i])
						end
					end
					self:RedisplayAura(i)
				end
			end
			PowaAurasOptions:UpdatePreviewColor(self.Auras[self.CurrentAuraId])
		end
	end
end

function PowaAurasOptions:BarThresholdSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	-- Don't use ~= checker!
	local aura = self.Auras[self.CurrentAuraId]
	aura.threshold = value
	PowaBarThresholdSliderEditBox:SetText(format("%.0f", value)..aura.RangeType)
end

function PowaAurasOptions:TextChanged()
	local oldText = PowaBarBuffName:GetText()
	local aura = self.Auras[self.CurrentAuraId]
	if oldText ~= aura.buffname then
		aura.buffname = PowaBarBuffName:GetText()
		aura.icon = ""
		PowaIconTexture:SetTexture("Interface\\Icons\\Inv_Misc_QuestionMark")
	end
end

function PowaAurasOptions:MultiIDChanged()
	local oldText = PowaBarMultiID:GetText()
	local aura = self.Auras[self.CurrentAuraId]
	if oldText ~= aura.multiids then
		aura.multiids = PowaBarMultiID:GetText()
		self:FindAllChildren()
	end
end

function PowaAurasOptions:TooltipCheckChanged()
	local oldText = PowaBarTooltipCheck:GetText()
	local aura = self.Auras[self.CurrentAuraId]
	if oldText ~= aura.tooltipCheck then
		aura.tooltipCheck = PowaBarTooltipCheck:GetText()
	end
end

function PowaAurasOptions:StacksTextChanged()
	local aura = self.Auras[self.CurrentAuraId]
	aura:SetStacks(PowaBarBuffStacks:GetText())
end

function PowaAurasOptions:UnitnTextChanged()
	local oldUnitnText = PowaBarUnitn:GetText()
	local aura = self.Auras[self.CurrentAuraId]
	if oldUnitnText ~= aura.unitn then
		aura.unitn = PowaBarUnitn:GetText()
	end
end

function PowaAurasOptions:CustomTextChanged()
	local aura = self.Auras[self.CurrentAuraId]
	aura.customname = PowaBarCustomTexName:GetText()
	if string.find(aura.customname, "%.") or not aura.customname or aura.customname == "" then
		aura.enablefullrotation = true
	else
		aura.enablefullrotation = false
		if aura.rotate ~= 0 and aura.rotate ~= 90 and aura.rotate ~= 180 and aura.rotate ~= 270 and aura.rotate ~= 360 then
			PowaBarAuraRotateSlider:SetValue(0)
		end
	end
	self:RedisplayAura(self.CurrentAuraId)
end

function PowaAurasOptions:CustomModelsChanged()
	local aura = self.Auras[self.CurrentAuraId]
	aura.modelcustompath = PowaBarCustomModelsEditBox:GetText()
	self:RedisplayAura(self.CurrentAuraId)
end

function PowaAurasOptions:AurasTextChanged()
	local aura = self.Auras[self.CurrentAuraId]
	aura.aurastext = PowaBarAurasText:GetText()
	self:RedisplayAura(self.CurrentAuraId)
end

function PowaAurasOptions:CustomSoundTextChanged(force)
	local oldCustomSound = PowaBarCustomSound:GetText()
	local aura = self.Auras[self.CurrentAuraId]
	if oldCustomSound ~= aura.customsound or force then
		aura.customsound = oldCustomSound
		if aura.customsound ~= "" then
			aura.sound = 0
			PowaDropDownSoundText:SetText(self.Sound[0])
			PowaDropDownSound2Text:SetText(self.Sound[30])
			PowaDropDownSoundButton:Disable()
			PowaDropDownSound2Button:Disable()
			local pathToSound
			if string.find(aura.customsound, "\\") then
				pathToSound = aura.customsound
			else
				pathToSound = PowaGlobalMisc.PathToSounds..aura.customsound
			end
			local played = PlaySoundFile(pathToSound, PowaMisc.SoundChannel)
		else
			PowaDropDownSoundButton:Enable()
			PowaDropDownSound2Button:Enable()
		end
	end
end

function PowaAurasOptions:CustomSoundEndTextChanged(force)
	local oldCustomSound = PowaBarCustomSoundEnd:GetText()
	local aura = self.Auras[self.CurrentAuraId]
	if oldCustomSound ~= aura.customsoundend or force then
		aura.customsoundend = oldCustomSound
		if aura.customsoundend ~= "" then
			aura.soundend = 0
			PowaDropDownSoundEndText:SetText(self.Sound[0])
			PowaDropDownSound2EndText:SetText(self.Sound[30])
			PowaDropDownSoundEndButton:Disable()
			PowaDropDownSound2EndButton:Disable()
			local pathToSound
			if string.find(aura.customsoundend, "\\") then
				pathToSound = aura.customsoundend
			else
				pathToSound = PowaGlobalMisc.PathToSounds..aura.customsoundend
			end
			local played = PlaySoundFile(pathToSound, PowaMisc.SoundChannel)
		else
			PowaDropDownSoundEndButton:Enable()
			PowaDropDownSound2EndButton:Enable()
		end
	end
end

function PowaAurasOptions:InverseChecked()
	local aura = self.Auras[self.CurrentAuraId]
	if PowaInverseButton:GetChecked() then
		aura.inverse = true
	else
		aura.inverse = false
	end
	if self.Auras[self.CurrentAuraId].Stacks and self.Auras[self.CurrentAuraId].Stacks.enabled == true then
		self.Auras[self.CurrentAuraId].Stacks:Dispose()
	end
	aura:HideShowTabs()
end

function PowaAurasOptions:IgnoreMajChecked()
	local aura = self.Auras[self.CurrentAuraId]
	if PowaIngoreCaseButton:GetChecked() then
		aura.ignoremaj = true
	else
		aura.ignoremaj = false
	end
end

function PowaAurasOptions:ExactChecked()
	local aura = self.Auras[self.CurrentAuraId]
	if PowaExactButton:GetChecked() then
		aura.exact = true
	else
		aura.exact = false
	end
end

function PowaAurasOptions:RandomColorChecked()
	local aura = self.Auras[self.CurrentAuraId]
	if PowaRandomColorButton:GetChecked() then
		aura.randomcolor = true
	else
		aura.randomcolor = false
	end
	if not aura.model and not aura.custommodel then
		self:RedisplayAura(self.CurrentAuraId)
	end
end

function PowaAurasOptions:ThresholdInvertChecked(owner)
	local aura = self.Auras[self.CurrentAuraId]
	if PowaThresholdInvertButton:GetChecked() then
		aura.thresholdinvert = true
	else
		aura.thresholdinvert = false
	end
end

function PowaAurasOptions:OwntexChecked()
	local aura = self.Auras[self.CurrentAuraId]
	if PowaOwntexButton:GetChecked() then
		aura.owntex = true
		aura.model = false
		aura.modelcustom = false
		aura.wowtex = false
		aura.customtex = false
		aura.textaura = false
		aura.enablefullrotation = false
		PowaWowTextureButton:SetChecked(false)
		PowaModelsButton:SetChecked(false)
		PowaCustomTextureButton:SetChecked(false)
		PowaTextAuraButton:SetChecked(false)
		PowaCustomModelsButton:SetChecked(false)
		if aura.rotate ~= 0 and aura.rotate ~= 90 and aura.rotate ~= 180 and aura.rotate ~= 270 and aura.rotate ~= 360 then
			PowaBarAuraRotateSlider:SetValue(0)
		end
		if not PowaBarAuraTextureSlider:IsVisible() then
			PowaBarAuraTextureSlider:Show()
		end
		PowaBlendModeDropDown:Show()
		PowaTextureStrataDropDown:Show()
		PowaTextureStrataSublevelSlider:Show()
		PowaBarAuraSymSlider:Show()
		PowaModelPositionZSlider:Hide()
		PowaModelPositionXSlider:Hide()
		PowaModelPositionYSlider:Hide()
		PowaBarCustomTexName:Hide()
		PowaBarAurasText:Hide()
		PowaFontButton:Hide()
		PowaBarAnimationSlider:Hide()
	else
		aura.owntex = false
	end
	self:InitPage(aura)
	self:RedisplayAura(self.CurrentAuraId)
end

function PowaAurasOptions:WowTexturesChecked()
	local aura = self.Auras[self.CurrentAuraId]
	if PowaWowTextureButton:GetChecked() then
		aura.wowtex = true
		aura.model = false
		aura.modelcustom = false
		aura.owntex = false
		aura.customtex = false
		aura.textaura = false
		if PowaBarAuraTextureSlider:GetValue() > #self.WowTextures then
			PowaBarAuraTextureSlider:SetValue(1)
		end
		PowaBarAuraTextureSlider:SetMinMaxValues(1, #self.WowTextures)
		PowaBarAuraTextureSliderHigh:SetText(#self.WowTextures)
		PowaOwntexButton:SetChecked(false)
		PowaModelsButton:SetChecked(false)
		PowaCustomTextureButton:SetChecked(false)
		PowaTextAuraButton:SetChecked(false)
		PowaCustomModelsButton:SetChecked(false)
		PowaBarAuraTextureSlider:Show()
		PowaBlendModeDropDown:Show()
		PowaTextureStrataDropDown:Show()
		PowaTextureStrataSublevelSlider:Show()
		PowaBarAuraSymSlider:Show()
		PowaModelPositionZSlider:Hide()
		PowaModelPositionXSlider:Hide()
		PowaModelPositionYSlider:Hide()
		PowaBarCustomTexName:Hide()
		PowaBarAurasText:Hide()
		PowaFontButton:Hide()
		PowaBarAnimationSlider:Hide()
	else
		aura.wowtex = false
		if PowaBarAuraTextureSlider:GetValue() > self.MaxTextures then
			PowaBarAuraTextureSlider:SetValue(1)
		end
		PowaBarAuraTextureSlider:SetMinMaxValues(1, self.MaxTextures)
		PowaBarAuraTextureSliderHigh:SetText(self.MaxTextures)
	end
	self:BarAuraSizeSliderChanged(PowaBarAuraSizeSlider)
	self:BarAuraTextureSliderChanged(PowaBarAuraTextureSlider)
	self:RedisplayAura(self.CurrentAuraId)
end

function PowaAurasOptions:ModelsChecked()
	local aura = self.Auras[self.CurrentAuraId]
	if PowaModelsButton:GetChecked() then
		aura.model = true
		aura.modelcustom = false
		aura.wowtex = false
		aura.owntex = false
		aura.customtex = false
		aura.textaura = false
		if PowaBarAuraTextureSlider:GetValue() > #PowaAurasModels then
			PowaBarAuraTextureSlider:SetValue(1)
		end
		PowaBarAuraTextureSlider:SetMinMaxValues(1, #PowaAurasModels)
		PowaBarAuraTextureSliderHigh:SetText(#PowaAurasModels)
		PowaWowTextureButton:SetChecked(false)
		PowaOwntexButton:SetChecked(false)
		PowaCustomTextureButton:SetChecked(false)
		PowaTextAuraButton:SetChecked(false)
		PowaCustomModelsButton:SetChecked(false)
		PowaModelPositionZSlider:Show()
		PowaModelPositionXSlider:Show()
		PowaModelPositionYSlider:Show()
		PowaBarAuraTextureSlider:Show()
		PowaBarAnimationSlider:Show()
		PowaBlendModeDropDown:Hide()
		PowaTextureStrataDropDown:Hide()
		PowaTextureStrataSublevelSlider:Hide()
		PowaBarCustomTexName:Hide()
		PowaBarCustomModelsEditBox:Hide()
		PowaBarAurasText:Hide()
		PowaFontButton:Hide()
		PowaBarAuraSymSlider:Hide()
	else
		aura.model = false
		PowaModelPositionZSlider:Hide()
		PowaModelPositionXSlider:Hide()
		PowaModelPositionYSlider:Hide()
		PowaBarAnimationSlider:Hide()
		PowaBlendModeDropDown:Show()
		PowaTextureStrataDropDown:Show()
		PowaTextureStrataSublevelSlider:Show()
		PowaBarAuraSymSlider:Show()
		if PowaBarAuraTextureSlider:GetValue() > self.MaxTextures then
			PowaBarAuraTextureSlider:SetValue(1)
		end
		PowaBarAuraTextureSlider:SetMinMaxValues(1, self.MaxTextures)
		PowaBarAuraTextureSliderHigh:SetText(self.MaxTextures)
	end
	self:BarAuraSizeSliderChanged(PowaBarAuraSizeSlider)
	self:BarAuraTextureSliderChanged(PowaBarAuraTextureSlider)
	self:RedisplayAura(self.CurrentAuraId)
end

function PowaAurasOptions:CustomModelsChecked()
	local aura = self.Auras[self.CurrentAuraId]
	if PowaCustomModelsButton:GetChecked() then
		aura.modelcustom = true
		aura.model = false
		aura.customtex = false
		aura.owntex = false
		aura.wowtex = false
		aura.textaura = false
		PowaModelPositionZSlider:Show()
		PowaModelPositionXSlider:Show()
		PowaModelPositionYSlider:Show()
		PowaBarAuraTextureSlider:Hide()
		PowaBarCustomModelsEditBox:Show()
		PowaBarAnimationSlider:Show()
		PowaBarCustomTexName:Hide()
		PowaBarCustomModelsEditBox:SetText(aura.modelcustompath)
		PowaOwntexButton:SetChecked(false)
		PowaModelsButton:SetChecked(false)
		PowaWowTextureButton:SetChecked(false)
		PowaTextAuraButton:SetChecked(false)
		PowaCustomTextureButton:SetChecked(false)
		PowaBarAurasText:Hide()
		PowaBlendModeDropDown:Hide()
		PowaTextureStrataDropDown:Hide()
		PowaTextureStrataSublevelSlider:Hide()
		PowaBarAuraSymSlider:Hide()
		PowaFontButton:Hide()
	else
		aura.modelcustom = false
		PowaModelPositionZSlider:Hide()
		PowaModelPositionXSlider:Hide()
		PowaModelPositionYSlider:Hide()
		PowaBarAnimationSlider:Hide()
		PowaBarCustomModelsEditBox:Hide()
		PowaBarAuraTextureSlider:Show()
		PowaBlendModeDropDown:Show()
		PowaTextureStrataDropDown:Show()
		PowaTextureStrataSublevelSlider:Show()
		PowaBarAuraSymSlider:Show()
	end
	self:BarAuraSizeSliderChanged(PowaBarAuraSizeSlider)
	self:BarAuraTextureSliderChanged(PowaBarAuraTextureSlider)
	self:RedisplayAura(self.CurrentAuraId)
end

function PowaAurasOptions:CustomTexturesChecked()
	local aura = self.Auras[self.CurrentAuraId]
	if PowaCustomTextureButton:GetChecked() then
		aura.customtex = true
		aura.model = false
		aura.modelcustom = false
		aura.owntex = false
		aura.wowtex = false
		aura.textaura = false
		PowaModelPositionZSlider:Hide()
		PowaModelPositionXSlider:Hide()
		PowaModelPositionYSlider:Hide()
		PowaBarAuraTextureSlider:Hide()
		PowaBarCustomTexName:Show()
		PowaBarCustomTexName:SetText(self.Auras[aura.id].customname)
		PowaOwntexButton:SetChecked(false)
		PowaModelsButton:SetChecked(false)
		PowaWowTextureButton:SetChecked(false)
		PowaTextAuraButton:SetChecked(false)
		PowaCustomModelsButton:SetChecked(false)
		PowaBarAurasText:Hide()
		PowaBlendModeDropDown:Show()
		PowaTextureStrataDropDown:Show()
		PowaTextureStrataSublevelSlider:Show()
		PowaBarAuraSymSlider:Show()
		PowaFontButton:Hide()
		PowaBarAnimationSlider:Hide()
	else
		aura.customtex = false
		PowaBarAuraTextureSlider:Show()
		PowaBarCustomTexName:Hide()
	end
	self:BarAuraSizeSliderChanged(PowaBarAuraSizeSlider)
	self:BarAuraTextureSliderChanged(PowaBarAuraTextureSlider)
	self:RedisplayAura(self.CurrentAuraId)
end

function PowaAurasOptions:TextAuraChecked()
	local aura = self.Auras[self.CurrentAuraId]
	if PowaTextAuraButton:GetChecked() then
		aura.textaura = true
		aura.model = false
		aura.modelcustom = false
		aura.owntex = false
		aura.wowtex = false
		aura.customtex = false
		PowaModelPositionZSlider:Hide()
		PowaModelPositionXSlider:Hide()
		PowaModelPositionYSlider:Hide()
		PowaBarAuraTextureSlider:Hide()
		PowaBlendModeDropDown:Show()
		PowaTextureStrataDropDown:Show()
		PowaTextureStrataSublevelSlider:Show()
		PowaBarAuraSymSlider:Show()
		PowaBarAurasText:Show()
		PowaFontButton:Show()
		PowaBarAurasText:SetText(aura.aurastext)
		PowaOwntexButton:SetChecked(false)
		PowaWowTextureButton:SetChecked(false)
		PowaModelsButton:SetChecked(false)
		PowaCustomTextureButton:SetChecked(false)
		PowaCustomModelsButton:SetChecked(false)
		PowaBarCustomTexName:Hide()
		PowaBarAnimationSlider:Hide()
		if (PowaBarAuraSizeSlider:GetValue() / 100) > 1.61 then
			PowaBarAuraSizeSlider:SetValue(1.61)
		end
	else
		aura.textaura = false
		PowaBarAuraTextureSlider:Show()
		PowaBarAurasText:Hide()
		PowaFontButton:Hide()
	end
	self:BarAuraSizeSliderChanged(PowaBarAuraSizeSlider)
	self:BarAuraTextureSliderChanged(PowaBarAuraTextureSlider)
	self:RedisplayAura(self.CurrentAuraId)
end

function PowaAurasOptions:DesaturationChecked()
	local aura = self.Auras[self.CurrentAuraId]
	if PowaDesaturateButton:GetChecked() then
		aura.desaturation = true
	else
		aura.desaturation = false
	end
	if not aura.model and not aura.custommodel then
		self:RedisplayAura(self.CurrentAuraId)
	end
end

function PowaAurasOptions:EnableFullRotationChecked()
	local aura = self.Auras[self.CurrentAuraId]
	if PowaEnableFullRotationButton:GetChecked() then
		aura.enablefullrotation = true
		PowaBarAuraRotateSlider:SetValueStep(1)
	else
		aura.enablefullrotation = false
		if aura.rotate ~= 0 and aura.rotate ~= 90 and aura.rotate ~= 180 and aura.rotate ~= 270 and aura.rotate ~= 360 then
			PowaBarAuraRotateSlider:SetValue(0)
		end
		PowaBarAuraRotateSlider:SetValueStep(90)
	end
	self:RedisplayAura(self.CurrentAuraId)
end

function PowaAurasOptions:RoundIconsChecked()
	local aura = self.Auras[self.CurrentAuraId]
	if PowaRoundIconsButton:GetChecked() then
		aura.roundicons = true
	else
		aura.roundicons = false
	end
	self:RedisplayAura(self.CurrentAuraId)
end

function PowaAurasOptions:TargetChecked()
	local aura = self.Auras[self.CurrentAuraId]
	if PowaTargetButton:GetChecked() then
		aura.target = true
	else
		aura.target = false
	end
	self:InitPage()
end

function PowaAurasOptions:TargetFriendChecked()
	local aura = self.Auras[self.CurrentAuraId]
	if PowaTargetFriendButton:GetChecked() then
		aura.targetfriend = true
	else
		aura.targetfriend = false
	end
	self:InitPage(aura)
end

function PowaAurasOptions:PartyChecked()
	local aura = self.Auras[self.CurrentAuraId]
	if PowaPartyButton:GetChecked() then
		aura.party = true
	else
		aura.party = false
	end
	self:InitPage(aura)
end

function PowaAurasOptions:GroupOrSelfChecked()
	local aura = self.Auras[self.CurrentAuraId]
	if PowaGroupOrSelfButton:GetChecked() then
		aura.groupOrSelf = true
	else
		aura.groupOrSelf = false
	end
	self:InitPage(aura)
end

function PowaAurasOptions:FocusChecked()
	local aura = self.Auras[self.CurrentAuraId]
	if PowaFocusButton:GetChecked() then
		aura.focus = true
	else
		aura.focus = false
	end
	self:InitPage(aura)
end

function PowaAurasOptions:RaidChecked()
	local aura = self.Auras[self.CurrentAuraId]
	if PowaRaidButton:GetChecked() then
		aura.raid = true
	else
		aura.raid = false
	end
	self:InitPage(aura)
end

function PowaAurasOptions:GroupAnyChecked()
	local aura = self.Auras[self.CurrentAuraId]
	if PowaGroupAnyButton:GetChecked() then
		aura.groupany = true
	else
		aura.groupany = false
	end
	self:InitPage(aura)
end

function PowaAurasOptions:OptunitnChecked()
	local aura = self.Auras[self.CurrentAuraId]
	if PowaOptunitnButton:GetChecked() then
		aura.optunitn = true
		PowaBarUnitn:Show()
		PowaBarUnitn:SetText(aura.unitn)
	else
		aura.optunitn = false
		PowaBarUnitn:Hide()
	end
end

-- Dropdown Menus
function PowaAurasOptions.DropDownMenu_Initialize(owner)
	local info
	local aura = PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId]
	local name = owner:GetName()
	if not aura then
		aura = PowaAurasOptions:AuraFactory(PowaAurasOptions.BuffTypes.Buff, 0)
	end
	if name == "PowaStrataDropDown" then
		UIDropDownMenu_SetWidth(owner, 125)
		for i = 1, #PowaAurasOptions.StrataList do
			local info = UIDropDownMenu_CreateInfo()
			info.text = PowaAurasOptions.StrataList[i]
			info.func = function(self)
				local strata = PowaAurasOptions.StrataList[i]
				local AuraID = PowaAurasOptions.CurrentAuraId
				if PowaAurasOptions.CurrentAuraId > 120 then
					PowaGlobalSet[AuraID]["strata"] = strata
				end
				PowaSet[AuraID]["strata"] = strata
				PowaStrataDropDownText:SetText(strata)
				UIDropDownMenu_SetSelectedName(PowaStrataDropDown, strata)
				PowaAurasOptions:RedisplayAura(PowaAurasOptions.CurrentAuraId)
			end
			UIDropDownMenu_AddButton(info)
		end
	elseif name == "PowaTextureStrataDropDown" then
		UIDropDownMenu_SetWidth(owner, 125)
		for i = 1, #PowaAurasOptions.TextureStrataList do
			local info = UIDropDownMenu_CreateInfo()
			info.text = PowaAurasOptions.TextureStrataList[i]
			info.func = function(self)
				local texturestrata = PowaAurasOptions.TextureStrataList[i]
				local AuraID = PowaAurasOptions.CurrentAuraId
				if PowaAurasOptions.CurrentAuraId > 120 then
					PowaGlobalSet[AuraID]["texturestrata"] = texturestrata
				end
				PowaSet[AuraID]["texturestrata"] = texturestrata
				PowaTextureStrataDropDownText:SetText(texturestrata)
				UIDropDownMenu_SetSelectedName(PowaTextureStrataDropDown, texturestrata)
				PowaAurasOptions:RedisplayAura(PowaAurasOptions.CurrentAuraId)
			end
			UIDropDownMenu_AddButton(info)
		end
	elseif name == "PowaBlendModeDropDown" then
		UIDropDownMenu_SetWidth(owner, 125)
		for i = 1, #PowaAurasOptions.BlendModeList do
			local info = UIDropDownMenu_CreateInfo()
			info.text = PowaAurasOptions.BlendModeList[i]
			info.func = function(self)
				local blendmode = PowaAurasOptions.BlendModeList[i]
				local AuraID = PowaAurasOptions.CurrentAuraId
				if PowaAurasOptions.CurrentAuraId > 120 then
					PowaGlobalSet[AuraID]["blendmode"] = blendmode
				end
				PowaSet[AuraID]["blendmode"] = blendmode
				PowaBlendModeDropDownText:SetText(blendmode)
				UIDropDownMenu_SetSelectedName(PowaBlendModeDropDown, blendmode)
				PowaAurasOptions:RedisplayAura(PowaAurasOptions.CurrentAuraId)
			end
			UIDropDownMenu_AddButton(info)
		end
	elseif name == "PowaSecondaryBlendModeDropDown" then
		UIDropDownMenu_SetWidth(owner, 190)
		for i = 1, #PowaAurasOptions.BlendModeList do
			local info = UIDropDownMenu_CreateInfo()
			info.text = PowaAurasOptions.BlendModeList[i]
			info.func = function(self)
				local blendmode = PowaAurasOptions.BlendModeList[i]
				local AuraID = PowaAurasOptions.CurrentAuraId
				if PowaAurasOptions.CurrentAuraId > 120 then
					PowaGlobalSet[AuraID]["secondaryblendmode"] = blendmode
				end
				PowaSet[AuraID]["secondaryblendmode"] = blendmode
				PowaSecondaryBlendModeDropDownText:SetText(blendmode)
				UIDropDownMenu_SetSelectedName(PowaSecondaryBlendModeDropDown, blendmode)
				PowaAurasOptions:RedisplayAura(PowaAurasOptions.CurrentAuraId)
			end
			UIDropDownMenu_AddButton(info)
		end
	elseif name == "PowaSecondaryStrataDropDown" then
		UIDropDownMenu_SetWidth(owner, 190)
		for i = 1, #PowaAurasOptions.StrataList do
			local info = UIDropDownMenu_CreateInfo()
			info.text = PowaAurasOptions.StrataList[i]
			info.func = function(self)
				local strata = PowaAurasOptions.StrataList[i]
				local AuraID = PowaAurasOptions.CurrentAuraId
				if PowaAurasOptions.CurrentAuraId > 120 then
					PowaGlobalSet[AuraID]["secondarystrata"] = strata
				end
				PowaSet[AuraID]["secondarystrata"] = strata
				PowaSecondaryStrataDropDownText:SetText(strata)
				UIDropDownMenu_SetSelectedName(PowaSecondaryStrataDropDown, strata)
				PowaAurasOptions:RedisplayAura(PowaAurasOptions.CurrentAuraId)
			end
			UIDropDownMenu_AddButton(info)
		end
	elseif name == "PowaSecondaryTextureStrataDropDown" then
		UIDropDownMenu_SetWidth(owner, 190)
		for i = 1, #PowaAurasOptions.TextureStrataList do
			local info = UIDropDownMenu_CreateInfo()
			info.text = PowaAurasOptions.TextureStrataList[i]
			info.func = function(self)
				local texturestrata = PowaAurasOptions.TextureStrataList[i]
				local AuraID = PowaAurasOptions.CurrentAuraId
				if PowaAurasOptions.CurrentAuraId > 120 then
					PowaGlobalSet[AuraID]["secondarytexturestrata"] = texturestrata
				end
				PowaSet[AuraID]["secondarytexturestrata"] = texturestrata
				PowaSecondaryTextureStrataDropDownText:SetText(texturestrata)
				UIDropDownMenu_SetSelectedName(PowaSecondaryTextureStrataDropDown, texturestrata)
				PowaAurasOptions:RedisplayAura(PowaAurasOptions.CurrentAuraId)
			end
			UIDropDownMenu_AddButton(info)
		end
	elseif name == "PowaGradientStyleDropDown" then
		UIDropDownMenu_SetWidth(owner, 120)
		for i = 1, #PowaAurasOptions.GradientStyleList do
			local info = UIDropDownMenu_CreateInfo()
			info.text = PowaAurasOptions.GradientStyleList[i]
			info.func = function(self)
				local gradientstyle = PowaAurasOptions.GradientStyleList[i]
				local AuraID = PowaAurasOptions.CurrentAuraId
				if PowaAurasOptions.CurrentAuraId > 120 then
					PowaGlobalSet[AuraID]["gradientstyle"] = gradientstyle
				end
				PowaSet[AuraID]["gradientstyle"] = gradientstyle
				PowaGradientStyleDropDownText:SetText(gradientstyle)
				UIDropDownMenu_SetSelectedName(PowaGradientStyleDropDown, gradientstyle)
				if not PowaAurasOptions.Auras[AuraID].model and not PowaAurasOptions.Auras[AuraID].custommodel then
					PowaAurasOptions:RedisplayAura(PowaAurasOptions.CurrentAuraId)
				end
			end
			UIDropDownMenu_AddButton(info)
		end
	elseif name == "PowaDropDownBuffType" then
		UIDropDownMenu_SetWidth(owner, 175)
		PowaAurasOptions:FillDropdownSorted(PowaAurasOptions.Text.AuraType, {func = PowaAurasOptions.DropDownMenu_OnClickBuffType, owner = owner})
		UIDropDownMenu_SetSelectedValue(PowaDropDownBuffType, aura.bufftype)
	elseif name == "PowaDropDownPowerType" then
		UIDropDownMenu_SetWidth(owner, 145)
		info = {func = PowaAurasOptions.DropDownMenu_OnClickPowerType, owner = owner}
		for i, name in pairs(PowaAurasOptions.Text.PowerType) do
			info.text = name
			info.value = i
			UIDropDownMenu_AddButton(info)
		end
		UIDropDownMenu_SetSelectedValue(PowaDropDownPowerType, aura.PowerType)
		--PowaAurasOptions:UpdateMainOption()
	elseif name == "PowaDropDownStance" then
		UIDropDownMenu_SetWidth(owner, 145)
		info = {func = PowaAurasOptions.DropDownMenu_OnClickStance, owner = owner}
		for k, v in pairs(PowaAurasOptions.PowaStance) do
			info.text = v
			info.value = k
			UIDropDownMenu_AddButton(info)
		end
		UIDropDownMenu_SetSelectedValue(PowaDropDownStance, aura.stance)
	elseif name == "PowaDropDownGTFO" then
		UIDropDownMenu_SetWidth(owner, 145)
		info = {func = PowaAurasOptions.DropDownMenu_OnClickGTFO, owner = owner}
		for i = 0, #(PowaAurasOptions.PowaGTFO) do
			info.text = PowaAurasOptions.PowaGTFO[i]
			info.value = i
			UIDropDownMenu_AddButton(info)
		end
		UIDropDownMenu_SetSelectedValue(PowaDropDownGTFO, aura.GTFO)
		aura:SetFixedIcon()
		--PowaAurasOptions:UpdateMainOption()
	elseif name == "PowaDropDownAnimBegin" then
		UIDropDownMenu_SetWidth(owner, 190)
		info = {func = PowaAurasOptions.DropDownMenu_OnClickBegin, owner = owner}
		for i = 0, #PowaAurasOptions.BeginAnimDisplay do
			info.text = PowaAurasOptions.BeginAnimDisplay[i]
			info.value = i
			UIDropDownMenu_AddButton(info)
		end
		UIDropDownMenu_SetSelectedValue(PowaDropDownAnimBegin, aura.begin)
	elseif name == "PowaDropDownAnimEnd" then
		UIDropDownMenu_SetWidth(owner, 190)
		info = {func = PowaAurasOptions.DropDownMenu_OnClickEnd, owner = owner}
		local aura = PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId]
		if aura ~= nil then
			if aura.UseOldAnimations == false then
				for i = 0, #PowaAurasOptions.EndAnimDisplay do
					info.text = PowaAurasOptions.EndAnimDisplay[i]
					info.value = i
					UIDropDownMenu_AddButton(info)
				end
			else
				for i = 0, #PowaAurasOptions.EndAnimDisplay - 2 do
					info.text = PowaAurasOptions.EndAnimDisplay[i]
					info.value = i
					UIDropDownMenu_AddButton(info)
				end
			end
			UIDropDownMenu_SetSelectedValue(PowaDropDownAnimEnd, aura.finish)
		else
			for i = 0, #PowaAurasOptions.EndAnimDisplay - 2 do
				info.text = PowaAurasOptions.EndAnimDisplay[i]
				info.value = i
				UIDropDownMenu_AddButton(info)
			end
			UIDropDownMenu_SetSelectedID(PowaDropDownAnimEnd, 1)
		end
	elseif name == "PowaDropDownAnim1" then
		UIDropDownMenu_SetWidth(owner, 190)
		local aura = PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId]
		if aura ~= nil then
			if aura.UseOldAnimations == false then
				for i = 1, #(PowaAurasOptions.Anim) do
					info = { }
					info.text = PowaAurasOptions.Anim[i]
					info.value = i
					info.func = PowaAurasOptions.DropDownMenu_OnClickAnim1
					UIDropDownMenu_AddButton(info)
				end
			else
				for i = 1, #(PowaAurasOptions.Anim) - 2 do
					info = { }
					info.text = PowaAurasOptions.Anim[i]
					info.value = i
					info.func = PowaAurasOptions.DropDownMenu_OnClickAnim1
					UIDropDownMenu_AddButton(info)
				end
			end
			UIDropDownMenu_SetSelectedValue(PowaDropDownAnim1, aura.anim1)
		else
			for i = 1, #(PowaAurasOptions.Anim) - 2 do
				info = { }
				info.text = PowaAurasOptions.Anim[i]
				info.value = i
				info.func = PowaAurasOptions.DropDownMenu_OnClickAnim1
				UIDropDownMenu_AddButton(info)
			end
			UIDropDownMenu_SetSelectedID(PowaDropDownAnim1, 1)
		end
	elseif name == "PowaDropDownAnim2" then
		UIDropDownMenu_SetWidth(owner, 190)
		local aura = PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId]
		if aura ~= nil then
			if aura.UseOldAnimations == false then
				for i = 0, #(PowaAurasOptions.Anim) do
					info = { }
					info.text = PowaAurasOptions.Anim[i]
					info.value = i
					info.func = PowaAurasOptions.DropDownMenu_OnClickAnim2
					UIDropDownMenu_AddButton(info)
				end
			else
				for i = 0, #(PowaAurasOptions.Anim) - 2 do
					info = { }
					info.text = PowaAurasOptions.Anim[i]
					info.value = i
					info.func = PowaAurasOptions.DropDownMenu_OnClickAnim2
					UIDropDownMenu_AddButton(info)
				end
			end
			UIDropDownMenu_SetSelectedValue(PowaDropDownAnim2, aura.anim2)
		else
			for i = 0, #(PowaAurasOptions.Anim) - 2 do
				info = { }
				info.text = PowaAurasOptions.Anim[i]
				info.value = i
				info.func = PowaAurasOptions.DropDownMenu_OnClickAnim2
				UIDropDownMenu_AddButton(info)
			end
			UIDropDownMenu_SetSelectedID(PowaDropDownAnim2, 1)
		end
	elseif name == "PowaDropDownSound" then
		UIDropDownMenu_SetWidth(owner, 210)
		info = {func = PowaAurasOptions.DropDownMenu_OnClickSound, owner = owner}
		for i = 0, 29 do
			if (PowaAurasOptions.Sound[i]) then
				info.text = PowaAurasOptions.Sound[i]
				info.value = i
				UIDropDownMenu_AddButton(info)
			end
		end
		if aura.sound < 30 then
			UIDropDownMenu_SetSelectedValue(PowaDropDownSound, aura.sound)
		else
			UIDropDownMenu_SetSelectedValue(PowaDropDownSound, 0)
		end
	elseif name == "PowaDropDownSound2" then
		UIDropDownMenu_SetWidth(owner, 210)
		info = {func = PowaAurasOptions.DropDownMenu_OnClickSound, owner = owner}
		for i = 30, #PowaAurasOptions.Sound do
			if (PowaAurasOptions.Sound[i]) then
				info.text = PowaAurasOptions.Sound[i]
				info.value = i
				UIDropDownMenu_AddButton(info)
			end
		end
		if aura.sound >= 30 then
			UIDropDownMenu_SetSelectedValue(PowaDropDownSound2, aura.sound)
		else
			UIDropDownMenu_SetSelectedValue(PowaDropDownSound2, 30)
		end
	elseif name == "PowaDropDownSoundEnd" then
		UIDropDownMenu_SetWidth(owner, 210)
		info = {func = PowaAurasOptions.DropDownMenu_OnClickSoundEnd, owner = owner}
		for i = 0, 29 do
			if (PowaAurasOptions.Sound[i]) then
				info.text = PowaAurasOptions.Sound[i]
				info.value = i
				UIDropDownMenu_AddButton(info)
			end
		end
		if aura.soundend < 30 then
			UIDropDownMenu_SetSelectedValue(PowaDropDownSoundEnd, aura.soundend)
		else
			UIDropDownMenu_SetSelectedValue(PowaDropDownSoundEnd, 0)
		end
	elseif name == "PowaDropDownSound2End" then
		UIDropDownMenu_SetWidth(owner, 210)
		info = {func = PowaAurasOptions.DropDownMenu_OnClickSoundEnd, owner = owner}
		for i = 30, #PowaAurasOptions.Sound do
			if (PowaAurasOptions.Sound[i]) then
				info.text = PowaAurasOptions.Sound[i]
				info.value = i
				UIDropDownMenu_AddButton(info)
			end
		end
		if aura.soundend >= 30 then
			UIDropDownMenu_SetSelectedValue(PowaDropDownSound2End, aura.soundend)
		else
			UIDropDownMenu_SetSelectedValue(PowaDropDownSound2End, 30)
		end
	elseif name == "PowaBuffTimerRelative" then
		UIDropDownMenu_SetWidth(owner, 190)
		info = {func = PowaAurasOptions.DropDownMenu_OnClickTimerRelative, owner = owner}
		for _, v in pairs({"NONE", "TOPLEFT", "TOP", "TOPRIGHT", "RIGHT", "BOTTOMRIGHT", "BOTTOM", "BOTTOMLEFT", "LEFT", "CENTER"}) do
			info.text = PowaAurasOptions.Text.Relative[v]
			info.value = v
			UIDropDownMenu_AddButton(info)
		end
		if aura.Timer then
			UIDropDownMenu_SetSelectedValue(PowaBuffTimerRelative, aura.Timer.Relative)
		end
	elseif name == "PowaBuffStacksRelative" then
		UIDropDownMenu_SetWidth(owner, 190)
		info = {func = PowaAurasOptions.DropDownMenu_OnClickStacksRelative, owner = owner}
		for _, v in pairs({"NONE", "TOPLEFT", "TOP", "TOPRIGHT", "RIGHT", "BOTTOMRIGHT", "BOTTOM", "BOTTOMLEFT", "LEFT", "CENTER"}) do
			info.text = PowaAurasOptions.Text.Relative[v]
			info.value = v
			UIDropDownMenu_AddButton(info)
		end
		if aura.Stacks then
			UIDropDownMenu_SetSelectedValue(PowaBuffStacksRelative, aura.Stacks.Relative)
		end
	end
end

function PowaAurasOptions:FillDropdownSorted(t, info)
	local names = PowaAurasOptions:CopyTable(t)
	local values = PowaAurasOptions:ReverseTable(names)
	table.sort(names)
	for _, name in pairs(names) do
		info.text = name
		info.value = values[name]
		UIDropDownMenu_AddButton(info)
	end
end

function PowaAurasOptions.DropDownMenu_OnClickBuffType(self)
	UIDropDownMenu_SetSelectedValue(self.owner, self.value)
	PowaAurasOptions:ChangeAuraType(PowaAurasOptions.CurrentAuraId, self.value)
end

function PowaAurasOptions:ChangeAuraType(id, newType)
	local oldAura = self.Auras[id]
	local showing = oldAura.Showing
	oldAura:Hide()
	if oldAura.Timer then
		oldAura.Timer:Dispose()
	end
	if oldAura.Stacks then
		oldAura.Stacks:Dispose()
	end
	if not oldAura.model and not oldAura.modelcustom then
		oldAura:Dispose()
	end
	local aura = self:AuraFactory(newType, id, oldAura)
	aura.icon = ""
	aura.Showing = showing
	aura:Init()
	self.Auras[id] = aura
	if self.CurrentAuraId > 120 then
		PowaGlobalSet[id] = aura
	end
	self:CalculateAuraSequence()
	if aura.textaura == true then
		self:RedisplayAura(aura.id)
	end
	local _, model = aura:CreateFrames()
	model:SetUnit("none")
	PowaAurasOptions.Models[aura.id] = nil
	PowaAurasOptions.SecondaryModels[aura.id] = nil
	if aura.bufftype == self.BuffTypes.Slots then
		if not PowaEquipmentSlotsFrame:IsVisible() then
			PowaEquipmentSlotsFrame:Show()
		end
	else
		if PowaEquipmentSlotsFrame:IsVisible() then
			PowaEquipmentSlotsFrame:Hide()
		end
	end
	if aura.CheckBoxes.PowaOwntexButton ~= 1 then
		aura.owntex = false
	end
	self:UpdateMainOption()
	self:RedisplayAura(aura.id)
	self:InitPage(aura)
end

function PowaAurasOptions:ShowSpinAtBeginningChecked(button)
	local aura = self.Auras[self.CurrentAuraId]
	if button:GetChecked() then
		aura.beginSpin = true
	else
		aura.beginSpin = false
	end
	self:RedisplayAura(self.CurrentAuraId)
end

function PowaAurasOptions:OldAnimationChecked(button)
	local aura = self.Auras[self.CurrentAuraId]
	if button:GetChecked() then
		aura.UseOldAnimations = true
		PowaShowSpinAtBeginning:Hide()
		if UIDropDownMenu_GetSelectedID(PowaDropDownAnimEnd) == 5 or UIDropDownMenu_GetSelectedID(PowaDropDownAnimEnd) == 6 then
			local aura = self.Auras[self.CurrentAuraId]
			UIDropDownMenu_SetSelectedID(PowaDropDownAnimEnd, 1)
			aura.finish = 0
		end
		if UIDropDownMenu_GetSelectedID(PowaDropDownAnim1) == 11 or UIDropDownMenu_GetSelectedID(PowaDropDownAnim1) == 12 then
			local aura = self.Auras[self.CurrentAuraId]
			UIDropDownMenu_SetSelectedID(PowaDropDownAnim1, 1)
			aura.anim1 = 1
		end
		if UIDropDownMenu_GetSelectedID(PowaDropDownAnim2) == 12 or UIDropDownMenu_GetSelectedID(PowaDropDownAnim2) == 13 then
			local aura = self.Auras[self.CurrentAuraId]
			UIDropDownMenu_SetSelectedID(PowaDropDownAnim2, 1)
			aura.anim2 = 0
		end
	else
		aura.UseOldAnimations = false
		PowaShowSpinAtBeginning:Show()
	end
	self:RedisplayAura(self.CurrentAuraId)
end

function PowaAurasOptions.DropDownMenu_OnClickAnim1(owner)
	local optionID = owner:GetID()
	local aura = PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId]
	UIDropDownMenu_SetSelectedID(PowaDropDownAnim1, optionID)
	--local optionName = UIDropDownMenu_GetText(PowaDropDownAnim1)
	--UIDropDownMenu_SetSelectedValue(PowaDropDownAnim1, optionName)
	aura.anim1 = optionID
	PowaAurasOptions:RedisplayAura(PowaAurasOptions.CurrentAuraId)
end

function PowaAurasOptions.DropDownMenu_OnClickAnim2(owner)
	local aura = PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId]
	local optionID = owner:GetID()
	local aura = PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId]
	if optionID == 1 then
		PowaAurasOptions.SecondaryModels[aura.id] = nil
	end
	UIDropDownMenu_SetSelectedID(PowaDropDownAnim2, optionID)
	--local optionName = UIDropDownMenu_GetText(PowaDropDownAnim2)
	--UIDropDownMenu_SetSelectedValue(PowaDropDownAnim2, optionName)
	aura.anim2 = optionID - 1
	PowaAurasOptions:RedisplayAura(PowaAurasOptions.CurrentAuraId)
end

function PowaAurasOptions.DropDownMenu_OnClickSound(self)
	UIDropDownMenu_SetSelectedValue(self.owner, self.value)
	if self.value == 0 or self.value == 30 or not PowaAurasOptions.Sound[self.value] then
		PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId].sound = 0
		return
	end
	PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId].sound = self.value
	if self.value < 30 then
		PowaDropDownSound2Text:SetText(PowaAurasOptions.Sound[30])
	else
		PowaDropDownSoundText:SetText(PowaAurasOptions.Sound[0])
	end
	if string.find(PowaAurasOptions.Sound[self.value], "%.") then
		PlaySoundFile(PowaGlobalMisc.PathToSounds..PowaAurasOptions.Sound[self.value], PowaMisc.SoundChannel)
	else
		PlaySound(PowaAurasOptions.Sound[self.value], PowaMisc.SoundChannel)
	end
end

function PowaAurasOptions.DropDownMenu_OnClickSoundEnd(self)
	UIDropDownMenu_SetSelectedValue(self.owner, self.value)
	if self.value == 0 or self.value == 30 or not PowaAurasOptions.Sound[self.value] then
		PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId].soundend = 0
		return
	end
	PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId].soundend = self.value
	if self.value < 30 then
		PowaDropDownSound2EndText:SetText(PowaAurasOptions.Sound[30])
	else
		PowaDropDownSoundEndText:SetText(PowaAurasOptions.Sound[0])
	end
	if string.find(PowaAurasOptions.Sound[self.value], "%.") then
		PlaySoundFile(PowaGlobalMisc.PathToSounds..PowaAurasOptions.Sound[self.value], PowaMisc.SoundChannel)
	else
		PlaySound(PowaAurasOptions.Sound[self.value], PowaMisc.SoundChannel)
	end
end

function PowaAurasOptions.DropDownMenu_OnClickStance(self)
	UIDropDownMenu_SetSelectedValue(self.owner, self.value)
	local aura = PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId]
	if aura.stance ~= self.value then
		aura.stance = self.value
		aura.icon = ""
	end
	PowaAurasOptions:InitPage(aura)
end

function PowaAurasOptions.DropDownMenu_OnClickGTFO(self)
	UIDropDownMenu_SetSelectedValue(self.owner, self.value)
	local aura = PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId]
	if aura.GTFO ~= self.value then
		aura.GTFO = self.value
		aura.icon = ""
	end
	PowaAurasOptions:InitPage(aura)
end

function PowaAurasOptions.DropDownMenu_OnClickPowerType(self)
	UIDropDownMenu_SetSelectedValue(self.owner, self.value)
	local aura = PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId]
	if aura.PowerType ~= self.value then
		aura.PowerType = self.value
		aura.icon = ""
		aura:Init()
	end
	PowaAurasOptions:InitPage(aura)
end

function PowaAurasOptions.DropDownMenu_OnClickBegin(self)
	UIDropDownMenu_SetSelectedID(self.owner, self.value + 1)
	local aura = PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId]
	if aura.begin ~= self.begin then
		aura.begin = self.value
	end
	PowaAurasOptions:RedisplayAura(PowaAurasOptions.CurrentAuraId)
end

function PowaAurasOptions.DropDownMenu_OnClickEnd(self)
	local optionID = self:GetID()
	local aura = PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId]
	UIDropDownMenu_SetSelectedID(PowaDropDownAnimEnd, optionID)
	if aura.finish ~= optionID - 1 then
		aura.finish = optionID - 1
	end
	PowaAurasOptions:RedisplayAura(PowaAurasOptions.CurrentAuraId)
end

-- Options Deplacement
function PowaAurasOptions:Bar_MouseDown(frame, button)
	if button == "LeftButton" then
		frame:StartMoving()
	end
end

function PowaAurasOptions:Bar_MouseUp(frame, button)
	frame:StopMovingOrSizing()
end

-- Color Picker
function PowaAurasOptions.SetColor()
	PowaAurasOptions:SetAuraColor(ColorPickerFrame:GetColorRGB())
end

function PowaAurasOptions.CancelColor()
	if ColorPickerFrame.previousValues and ColorPickerFrame.previousValues.r and ColorPickerFrame.previousValues.g and ColorPickerFrame.previousValues.b then
		PowaAurasOptions:SetAuraColor(ColorPickerFrame.previousValues.r, ColorPickerFrame.previousValues.g, ColorPickerFrame.previousValues.b)
	end
end

function PowaAurasOptions:SetAuraColor(r, g, b)
	local swatch = _G[ColorPickerFrame.Button:GetName().."NormalTexture"]
	swatch:SetVertexColor(r, g, b)
	local frame = _G[ColorPickerFrame.Button:GetName().."_SwatchBg"]
	local aura = self.Auras[self.CurrentAuraId]
	frame.r = r
	frame.g = g
	frame.b = b
	ColorPickerFrame.Source.r = r
	ColorPickerFrame.Source.g = g
	ColorPickerFrame.Source.b = b
	if ColorPickerFrame.setTexture then
		if not aura.model and not aura.custommodel then
			AuraTexture:SetVertexColor(r, g, b)
		end
	end
	if not aura.model and not aura.custommodel then
		self:RedisplayAura(self.CurrentAuraId)
	end
end

function PowaAurasOptions:OpenColorPicker(control, source, setTexture)
	CloseMenus()
	if ColorPickerFrame:IsVisible() then
		PowaAurasOptions.CancelColor()
		ColorPickerFrame:Hide()
	else
		local button = PowaColor_SwatchBg
		ColorPickerFrame.Source = source
		ColorPickerFrame.Button = control
		ColorPickerFrame.setTexture = setTexture
		ColorPickerFrame.func = self.SetColor
		ColorPickerFrame:SetColorRGB(button.r, button.g, button.b)
		ColorPickerFrame.previousValues = {r = button.r, g = button.g, b = button.b, a = button.opacity}
		ColorPickerFrame.cancelFunc = self.CancelColor
		ColorPickerFrame:SetPoint("TOPLEFT", "PowaBarConfigFrame", "TOPRIGHT", 0, 0)
		ColorPickerFrame:Show()
	end
end

function PowaAurasOptions.SetGradientColor()
	PowaAurasOptions:SetGradientAuraColor(ColorPickerFrame:GetColorRGB())
end

function PowaAurasOptions.CancelGradientColor()
	if ColorPickerFrame.previousGradientValues and ColorPickerFrame.previousGradientValues.r and ColorPickerFrame.previousGradientValues.g and ColorPickerFrame.previousGradientValues.b then
		PowaAurasOptions:SetGradientAuraColor(ColorPickerFrame.previousGradientValues.r, ColorPickerFrame.previousGradientValues.g, ColorPickerFrame.previousGradientValues.b)
	end
end

function PowaAurasOptions:SetGradientAuraColor(r, g, b)
	local swatch = _G[ColorPickerFrame.GradientButton:GetName().."NormalTexture"]
	swatch:SetVertexColor(r, g, b)
	local frame = _G[ColorPickerFrame.GradientButton:GetName().."_SwatchBg"]
	local aura = self.Auras[self.CurrentAuraId]
	frame.r = r
	frame.g = g
	frame.b = b
	aura.gr = r
	aura.gg = g
	aura.gb = b
	if not aura.model and not aura.custommodel then
		self:RedisplayAura(self.CurrentAuraId)
	end
end

function PowaAurasOptions:OpenGradientColorPicker(control, source, setTexture)
	CloseMenus()
	if ColorPickerFrame:IsVisible() then
		PowaAurasOptions.CancelGradientColor()
		ColorPickerFrame:Hide()
	else
		local button = PowaGradientColor_SwatchBg
		ColorPickerFrame.GradientSource = source
		ColorPickerFrame.GradientButton = control
		ColorPickerFrame.setTexture = setTexture
		ColorPickerFrame.func = self.SetGradientColor
		ColorPickerFrame:SetColorRGB(button.r, button.g, button.b)
		ColorPickerFrame.previousGradientValues = {r = button.r, g = button.g, b = button.b, a = button.opacity}
		ColorPickerFrame.cancelFunc = self.CancelGradientColor
		ColorPickerFrame:SetPoint("TopLeft", "PowaBarConfigFrame", "TopRight", 0, 0)
		ColorPickerFrame:Show()
	end
end

-- Font Selector
function PowaAurasOptions:FontSelectorOnShow(owner)
	owner:SetBackdropBorderColor(0.9, 1.0, 0.95)
	owner:SetBackdropColor(0.6, 0.6, 0.6)
end

function PowaAurasOptions:OpenFontSelector(owner)
	CloseMenus()
	if FontSelectorFrame:IsVisible() then
		FontSelectorFrame:Hide()
	else
		FontSelectorFrame.selectedFont = self.Auras[self.CurrentAuraId].aurastextfont
		FontSelectorFrame:Show()
	end
end

function PowaAurasOptions:FontSelectorOkay(owner)
	local aura = self.Auras[self.CurrentAuraId]
	if FontSelectorFrame.selectedFont then
		aura.aurastextfont = FontSelectorFrame.selectedFont
	else
		aura.aurastextfont = 1
	end
	self:RedisplayAura(self.CurrentAuraId)
	self:FontSelectorClose(owner)
end

function PowaAurasOptions:FontSelectorCancel(owner)
	self:FontSelectorClose(owner)
end

function PowaAurasOptions:FontSelectorClose(owner)
	FontSelectorFrame:Hide()
end

function PowaAurasOptions:FontButton_OnClick(owner)
	FontSelectorFrame.selectedFont = _G["FontSelectorEditorScrollButton"..owner:GetID()].font
	self:FontScrollBar_Update(owner)
end

function PowaAurasOptions.FontScrollBar_Update(owner)
	local fontOffset = FauxScrollFrame_GetOffset(FontSelectorEditorScrollFrame)
	local fontIndex
	local fontName, namestart, nameend
	for i = 1, 10, 1 do
		fontIndex = fontOffset + i
		fontName = PowaAurasOptions.Fonts[fontIndex]
		fontText = _G["FontSelectorEditorScrollButton"..i.."Text"]
		fontButton = _G["FontSelectorEditorScrollButton"..i]
		fontButton.font = fontIndex
		namestart = string.find(fontName, "\\", 1, true)
		nameend = string.find(fontName, ".", 1, true)
		if namestart and nameend and nameend > namestart then
			fontName = string.sub(fontName, namestart + 1, nameend - 1)
			while string.find(fontName, "\\", 1, true) do
				namestart = string.find(fontName, "\\", 1, true)
				fontName = string.sub(fontName, namestart + 1)
			end
		end
		fontText:SetFont(PowaAurasOptions.Fonts[fontIndex], 14, "Outline, Monochrome")
		fontText:SetText(fontName)
		if FontSelectorFrame.selectedFont == fontIndex then
			fontButton:LockHighlight()
		else
			fontButton:UnlockHighlight()
		end
	end
	FauxScrollFrame_Update(FontSelectorEditorScrollFrame, #PowaAurasOptions.Fonts, 10, 16 )
end

function PowaAurasOptions:EditorShow()
	if PowaBarConfigFrame:IsVisible() then
		self:EditorClose()
		return
	end
	local aura = self.Auras[self.CurrentAuraId]
	local owner = _G["PowaIcone"..self.CurrentAuraId]
	if aura then
		if not aura.Showing then
			aura.Active = true
			aura:CreateFrames()
			self.SecondaryAuras[aura.id] = nil
			self:DisplayAura(aura.id)
			if not aura.off then
				if owner then
					owner:SetAlpha(1.0)
				end
			end
		end
		self:InitPage(aura)
		PowaBarConfigFrame:Show()
		PlaySound("TalentScreenOpen", PowaMisc.SoundChannel)
	end
end

function PowaAurasOptions:EditorClose()
	if PowaBarConfigFrame:IsVisible() then
		if FontSelectorFrame:IsVisible() then
			FontSelectorFrame:Hide()
		end
		if ColorPickerFrame:IsVisible() then
			self.CancelColor()
			ColorPickerFrame:Hide()
		end
		PowaBarConfigFrame:Hide()
		PlaySound("TalentScreenClose", PowaMisc.SoundChannel)
	end
end

-- Advanced Options
function PowaAurasOptions:ShowTimerChecked(button)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if button:GetChecked() then
		self.Auras[self.CurrentAuraId].Timer.enabled = true
		self:CreateTimerFrameIfMissing(self.CurrentAuraId)
	else
		self.Auras[self.CurrentAuraId].Timer.enabled = false
		self.Auras[self.CurrentAuraId].Timer:Dispose()
	end
	self:RedisplayAura(self.CurrentAuraId)
end

function PowaAurasOptions:TimerSizeSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if value ~= self.Auras[self.CurrentAuraId].Timer.h then
		self.Auras[self.CurrentAuraId].Timer.h = value
	end
	--self:CreateTimerFrameIfMissing(self.CurrentAuraId)
end

function PowaAurasOptions:TimerAlphaSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if value ~= self.Auras[self.CurrentAuraId].Timer.a then
		self.Auras[self.CurrentAuraId].Timer.a = value
	end
	--self:CreateTimerFrameIfMissing(self.CurrentAuraId)
end

function PowaAurasOptions:TimerCoordXSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if value ~= self.Auras[self.CurrentAuraId].Timer.x then
		self.Auras[self.CurrentAuraId].Timer.x = value
	end
	--self:CreateTimerFrameIfMissing(self.CurrentAuraId)
end

function PowaAurasOptions:TimerCoordYSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if value ~= self.Auras[self.CurrentAuraId].Timer.y then
		self.Auras[self.CurrentAuraId].Timer.y = value
	end
	--self:CreateTimerFrameIfMissing(self.CurrentAuraId)
end

function PowaAurasOptions:PowaTimerInvertAuraSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	local text
	if self.Auras[self.CurrentAuraId].InvertTimeHides then
		text = self.Text.nomTimerHideAura
		slider.aide = PowaAurasOptions.Text.aidePowaTimerHideAuraSlider
	else
		text = self.Text.nomTimerInvertAura
		slider.aide = PowaAurasOptions.Text.aidePowaTimerInvertAuraSlider
	end
	if value ~= self.Auras[self.CurrentAuraId].InvertAuraBelow then
		self.Auras[self.CurrentAuraId].InvertAuraBelow = value
	end
	--self:CreateTimerFrameIfMissing(self.CurrentAuraId)
end

function PowaAurasOptions:TimerDurationSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if value ~= self.Auras[self.CurrentAuraId].timerduration then
		self.Auras[self.CurrentAuraId].timerduration = value
	end
	--self:CreateTimerFrameIfMissing(self.CurrentAuraId)
end

function PowaAurasOptions.DropDownMenu_OnClickTimerRelative(self)
	UIDropDownMenu_SetSelectedValue(self.owner, self.value)
	local timer = PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId].Timer
	timer.x = 0
	timer.y = 0
	timer.Relative = self.value
	timer:Dispose()
end

function PowaAurasOptions:TimerChecked(button, setting)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	local aura = self.Auras[self.CurrentAuraId]
	if button:GetChecked() then
		aura.Timer[setting] = true
	else
		aura.Timer[setting] = false
	end
	aura.Timer:Dispose()
	aura.Timer:SetShowOnAuraHide(aura)
	--self:CreateTimerFrameIfMissing(self.CurrentAuraId)
end

function PowaAurasOptions:SettingChecked(button, setting)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if button:GetChecked() then
		self.Auras[self.CurrentAuraId][setting] = true
	else
		self.Auras[self.CurrentAuraId][setting] = false
	end
end

function PowaAurasOptions:TimerTransparentChecked(button)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if button:GetChecked() then
		self.Auras[self.CurrentAuraId].Timer.Transparent = true
	else
		self.Auras[self.CurrentAuraId].Timer.Transparent = false
	end
	self.Auras[self.CurrentAuraId].Timer:Dispose()
	--self:CreateTimerFrameIfMissing(self.CurrentAuraId)
end

-- Stacks
function PowaAurasOptions:ShowStacksChecked(button)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if button:GetChecked() then
		self.Auras[self.CurrentAuraId].Stacks.enabled = true
	else
		self.Auras[self.CurrentAuraId].Stacks.enabled = false
		self.Auras[self.CurrentAuraId].Stacks:Dispose()
	end
	self:RedisplayAura(self.CurrentAuraId)
end

function PowaAurasOptions:StacksAlphaSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if value ~= self.Auras[self.CurrentAuraId].Stacks.a then
		self.Auras[self.CurrentAuraId].Stacks.a = value
	end
end

function PowaAurasOptions:StacksSizeSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if value ~= self.Auras[self.CurrentAuraId].Stacks.h then
		self.Auras[self.CurrentAuraId].Stacks.h = value
	end
end

function PowaAurasOptions:StacksCoordXSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if value ~= self.Auras[self.CurrentAuraId].Stacks.x then
		self.Auras[self.CurrentAuraId].Stacks.x = value
	end
end


function PowaAurasOptions:StacksCoordYSliderChanged(slider, value)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	if value ~= self.Auras[self.CurrentAuraId].Stacks.y then
		self.Auras[self.CurrentAuraId].Stacks.y = value
	end
end

function PowaAurasOptions.DropDownMenu_OnClickStacksRelative(self)
	UIDropDownMenu_SetSelectedValue(self.owner, self.value)
	local stacks = PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId].Stacks
	stacks.x = 0
	stacks.y = 0
	stacks.Relative = self.value
	stacks:Dispose()
end

function PowaAurasOptions:StacksChecked(button, setting)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	if button:GetChecked() then
		self.Auras[self.CurrentAuraId].Stacks[setting] = true
	else
		self.Auras[self.CurrentAuraId].Stacks[setting] = false
	end
	self.Auras[self.CurrentAuraId].Stacks:Dispose()
end

function PowaAuras_CommandLine(msg)
	if msg == "dump" then
		local dumpLoaded = PowaAurasOptions.Dump
		if dumpLoaded then
			PowaAurasOptions:Dump()
			PowaAurasOptions:Message("State dumped to:")
			PowaAurasOptions:Message("WTF\\Account\\<ACCOUNT>\\"..GetRealmName().."\\"..UnitName("player").."\\SavedVariables\\PowerAuras.lua")
			PowaAurasOptions:Message("You must log-out to save the values to disk.")
		else
			PowaAurasOptions:Message("Function is not loaded.")
		end
	elseif msg == "cleardump" then
		local dumpLoaded = PowaAurasOptions.Dump
		if dumpLoaded then
			PowaAurasOptions:ClearDump()
			PowaAurasOptions:Message("State dump cleared.")
		else
			PowaAurasOptions:Message("Function is not loaded.")
		end
	elseif msg == "update" or msg == "upgrade" then
		PowaAurasOptions:UpdateOldAuras()
	elseif msg == "toggle" or msg == "tog" then
		PowaAurasOptions:Toggle()
	elseif msg == "showbuffs" or msg == "buffs" then
		PowaAurasOptions:ShowAurasOnUnit("Buffs", "HELPFUL")
	elseif msg == "showdebuffs" or msg == "debuffs" then
		PowaAurasOptions:ShowAurasOnUnit("Debuffs", "HARMFUL")
	else
		PowaAurasOptions:MainOptionShow()
	end
end

function PowaAurasOptions:InitalizeOnMenuOpen()
	UIDropDownMenu_Initialize(PowaStrataDropDown, PowaAurasOptions.DropDownMenu_Initialize)
	UIDropDownMenu_Initialize(PowaTextureStrataDropDown, PowaAurasOptions.DropDownMenu_Initialize)
	UIDropDownMenu_Initialize(PowaBlendModeDropDown, PowaAurasOptions.DropDownMenu_Initialize)
	UIDropDownMenu_Initialize(PowaGradientStyleDropDown, PowaAurasOptions.DropDownMenu_Initialize)
	UIDropDownMenu_Initialize(PowaDropDownBuffType, PowaAurasOptions.DropDownMenu_Initialize)
	UIDropDownMenu_Initialize(PowaDropDownPowerType, PowaAurasOptions.DropDownMenu_Initialize)
	UIDropDownMenu_Initialize(PowaDropDownStance, PowaAurasOptions.DropDownMenu_Initialize)
	UIDropDownMenu_Initialize(PowaDropDownGTFO, PowaAurasOptions.DropDownMenu_Initialize)
	UIDropDownMenu_Initialize(PowaDropDownAnimBegin, PowaAurasOptions.DropDownMenu_Initialize)
	UIDropDownMenu_Initialize(PowaDropDownAnimEnd, PowaAurasOptions.DropDownMenu_Initialize)
	UIDropDownMenu_Initialize(PowaDropDownAnim1, PowaAurasOptions.DropDownMenu_Initialize)
	UIDropDownMenu_Initialize(PowaDropDownAnim2, PowaAurasOptions.DropDownMenu_Initialize)
	UIDropDownMenu_Initialize(PowaSecondaryBlendModeDropDown, PowaAurasOptions.DropDownMenu_Initialize)
	UIDropDownMenu_Initialize(PowaSecondaryStrataDropDown, PowaAurasOptions.DropDownMenu_Initialize)
	UIDropDownMenu_Initialize(PowaSecondaryTextureStrataDropDown, PowaAurasOptions.DropDownMenu_Initialize)
	UIDropDownMenu_Initialize(PowaDropDownSound, PowaAurasOptions.DropDownMenu_Initialize)
	UIDropDownMenu_Initialize(PowaDropDownSound2, PowaAurasOptions.DropDownMenu_Initialize)
	UIDropDownMenu_Initialize(PowaDropDownSoundEnd, PowaAurasOptions.DropDownMenu_Initialize)
	UIDropDownMenu_Initialize(PowaDropDownSound2End, PowaAurasOptions.DropDownMenu_Initialize)
end

function PowaAurasOptions:ShowAurasOnUnit(display, auraType)
	local index = 1
	local unit = "player"
	if UnitExists("target") then
		unit = "target"
	end
	PowaAurasOptions:Message(display.." on "..unit)
	local Name, _, _, Applications, Type, Duration, Expires, Source, Stealable, shouldConsolidate, spellId = UnitAura(unit, index, auraType)
	while Name do
		PowaAurasOptions:Message(index..": "..Name.." (SpellID = "..spellId..")")
		index = index + 1
		Name, _, _, Applications, Type, Duration, Expires, Source, Stealable, shouldConsolidate, spellId = UnitAura(unit, index, auraType)
	end
end

-- Enable/Disable Options Functions
function PowaAurasOptions:DisableSlider(slider)
	_G[slider]:EnableMouse(false)
	_G[slider.."Text"]:SetTextColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b)
	_G[slider.."Low"]:SetTextColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b)
	_G[slider.."High"]:SetTextColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b)
end

function PowaAurasOptions:EnableSlider(slider)
	_G[slider]:EnableMouse(true)
	_G[slider.."Text"]:SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b)
	_G[slider.."Low"]:SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b)
	_G[slider.."High"]:SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b)
end

function PowaAurasOptions:DisableTextfield(textfield)
	_G[textfield]:Hide()
	_G[textfield.."Text"]:SetTextColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b)
end

function PowaAurasOptions:EnableTextfield(textfield)
	_G[textfield]:Show()
	_G[textfield.."Text"]:SetTextColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b)
end

function PowaAurasOptions:DisableCheckBox(checkBox)
	_G[checkBox]:Disable()
	_G[checkBox.."Text"]:SetTextColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b)
end

function PowaAurasOptions:EnableCheckBox(checkBox, color)
	_G[checkBox]:Enable()
	if not color then
		color = NORMAL_FONT_COLOR
	end
	_G[checkBox.."Text"]:SetTextColor(color.r, color.g, color.b)
end

function PowaAurasOptions:HideCheckBox(checkBox)
	_G[checkBox]:Hide()
end

function PowaAurasOptions:ShowCheckBox(checkBox)
	_G[checkBox]:Show()
end

-- Blizzard Addon
function PowaAurasOptions:EnableChecked()
	if PowaEnableButton:GetChecked() then
		self:Toggle(true)
	else
		self:MainOptionClose()
		self:Toggle(false)
	end
end

function PowaAurasOptions:MiscChecked(button, setting)
	if button:GetChecked() then
		PowaMisc[setting] = true
	else
		PowaMisc[setting] = false
	end
end

function PowaAurasOptions:GlobalMiscChecked(button, setting)
	if button:GetChecked() then
		PowaGlobalMisc[setting] = true
	else
		PowaGlobalMisc[setting] = false
	end
end

local function OptionsOK()
	PowaMisc.OnUpdateLimit = (100 - PowaOptionsUpdateSlider2:GetValue()) / 200
	PowaMisc.AnimationLimit = (100 - PowaOptionsTimerUpdateSlider2:GetValue()) / 1000
	PowaMisc.UserSetMaxTextures = PowaOptionsTextureCount:GetValue()
	if PowaMisc.OverrideMaxTextures then
		PowaAurasOptions.MaxTextures = PowaMisc.UserSetMaxTextures
	else
		PowaAurasOptions.MaxTextures = PowaAurasOptions.TextureCount
	end
	PowaAurasOptions:EnableChecked()
	PowaAurasOptions:MiscChecked(PowaDebugButton, "Debug")
	PowaAurasOptions:MiscChecked(PowaTimerRoundingButton, "TimerRoundUp")
	PowaAurasOptions:GlobalMiscChecked(PowaBlockIncomingAurasButton, "BlockIncomingAuras")
	PowaAurasOptions:GlobalMiscChecked(PowaFixExportsButton, "FixExports")
	local newDefaultTimerTexture = UIDropDownMenu_GetSelectedValue(PowaDropDownDefaultTimerTexture)
	if newDefaultTimerTexture ~= PowaMisc.DefaultTimerTexture then
		PowaMisc.DefaultTimerTexture = newDefaultTimerTexture
		for auraId, aura in pairs(PowaAurasOptions.Auras) do
			if aura.Timer and aura.Timer.Texture == "Default" then
				aura.Timer:Hide()
				PowaAurasOptions.TimerFrame[auraId] = { }
				PowaAurasOptions:CreateTimerFrame(auraId, 1)
				PowaAurasOptions:CreateTimerFrame(auraId, 2)
			end
		end
	end
	local newDefaultStacksTexture = UIDropDownMenu_GetSelectedValue(PowaDropDownDefaultStacksTexture)
	if newDefaultStacksTexture ~= PowaMisc.DefaultStacksTexture then
		PowaMisc.DefaultStacksTexture = newDefaultStacksTexture
		for auraId, aura in pairs(PowaAurasOptions.Auras) do
			if aura.Stacks and aura.Stacks.Texture == "Default" then
				aura.Stacks:Hide()
				PowaAurasOptions.StacksFrames[auraId].texture:SetTexture(aura.Stacks:GetTexture())
			end
		end
	end
	PowaGlobalMisc.PathToSounds = PowaCustomSoundPath:GetText()
	PowaGlobalMisc.PathToAuras = PowaCustomAuraPath:GetText()
	PowaAurasOptions.ModTest = false
	PowaAurasOptions.DoCheck.All = true
end

local function OptionsCancel()
	PowaAurasOptions.ModTest = false
	PowaAurasOptions.DoCheck.All = true
end

local function OptionsDefault()
	for k, v in pairs(PowaAurasOptions.PowaMiscDefault) do
		PowaMisc[k] = v
	end
	for k, v in pairs(PowaAurasOptions.PowaGlobalMiscDefault) do
		PowaGlobalMisc[k] = v
	end
	self:DisplayText("Power Aura Options Reset to Defaults")
end

local function OptionsRefresh()
	PowaOptionsUpdateSlider2:SetValue(100 - 200 * PowaMisc.OnUpdateLimit)
	PowaOptionsTimerUpdateSlider2:SetValue(100 - 1000 * PowaMisc.AnimationLimit)
	PowaOptionsTextureCount:SetValue(PowaMisc.UserSetMaxTextures)
	PowaOverrideTextureCountButton:SetChecked(PowaMisc.OverrideMaxTextures)
	PowaEnableButton:SetChecked(PowaMisc.Disabled ~= true)
	PowaDebugButton:SetChecked(PowaMisc.Debug)
	PowaTimerRoundingButton:SetChecked(PowaMisc.TimerRoundUp)
	PowaAllowInspectionsButton:SetChecked(PowaMisc.AllowInspections)
	PowaBlockIncomingAurasButton:SetChecked(PowaGlobalMisc.BlockIncomingAuras)
	PowaFixExportsButton:SetChecked(PowaGlobalMisc.FixExports)
	UIDropDownMenu_SetSelectedValue(PowaDropDownDefaultTimerTexture, PowaMisc.DefaultTimerTexture)
	UIDropDownMenu_SetSelectedValue(PowaDropDownDefaultStacksTexture, PowaMisc.DefaultStacksTexture)
	PowaCustomSoundPath:SetText(PowaGlobalMisc.PathToSounds)
	PowaCustomSoundPath:SetCursorPosition(0)
	PowaCustomAuraPath:SetText(PowaGlobalMisc.PathToAuras)
	PowaCustomAuraPath:SetCursorPosition(0)
end

function PowaOptionsCpuFrame2_OnLoad(panel)
	panel.name = GetAddOnMetadata("PowerAuras", "Title")
	panel.okay = function (self) OptionsOK() end
	panel.cancel = function (self) OptionsCancel() end
	panel.default = function (self) OptionsDefault() end
	panel.refresh = function (self) OptionsRefresh() end
	InterfaceOptions_AddCategory(panel)
end

function PowaAurasOptions:PowaOptionsUpdateSliderChanged2(slider, value)
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	PowaOptionsUpdateSlider2Text:SetText(self.Text.nomUpdateSpeed..": "..value.."%")
end

function PowaAurasOptions:PowaOptionsTimerUpdateSliderChanged2(slider, value)
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	PowaOptionsTimerUpdateSlider2Text:SetText(self.Text.nomTimerUpdate..": "..value.."%")
end

function PowaAurasOptions:PowaOptionsMaxTexturesSliderChanged(slider, value)
	if not slider._onsetting then
		slider._onsetting = true
		slider:SetValue(slider:GetValue())
		value = slider:GetValue()
		slider._onsetting = false
	else
		return
	end
	PowaOptionsTextureCountText:SetText(self.Text.nomTextureCount..": "..value)
end

function PowaAurasOptions.DropDownDefaultTimerMenu_Initialize(owner)
	PowaAurasOptions:InitializeTextureDropdown(owner, PowaAurasOptions.DropDownMenu_OnClickDefaultTimer, PowaMisc.DefaultTimerTexture, false)
end

function PowaAurasOptions.DropDownDefaultStacksMenu_Initialize(owner)
	PowaAurasOptions:InitializeTextureDropdown(owner, PowaAurasOptions.DropDownMenu_OnClickDefaultStacks, PowaMisc.DefaultStacksTexture, false)
end

function PowaAurasOptions.DropDownMenu_OnClickDefaultTimer(self)
	UIDropDownMenu_SetSelectedValue(self.owner, self.value)
	PowaMisc.DefaultTimerTexture = self.value
end

function PowaAurasOptions.DropDownMenu_OnClickDefaultStacks(self)
	UIDropDownMenu_SetSelectedValue(self.owner, self.value)
	PowaMisc.DefaultStacksTexture = self.value
end

function PowaAurasOptions:InitializeTextureDropdown(owner, onClick, currentValue, addDefaultOption)
	UIDropDownMenu_SetWidth(owner, 190)
	local info = {func = onClick, owner = owner, text = PowaAurasOptions.Text.Default}
	if addDefaultOption then
		UIDropDownMenu_AddButton(info)
	end
	for k, v in pairs(PowaAurasOptions.TimerTextures) do
		info.text = v
		info.value = v
		UIDropDownMenu_AddButton(info)
	end
	UIDropDownMenu_SetSelectedValue(owner, currentValue)
end

function PowaAurasOptions.DropDownTimerMenu_Initialize(owner)
	local aura = PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId]
	if not aura or not aura.Timer then
		return
	end
	PowaAurasOptions:InitializeTextureDropdown(owner, PowaAurasOptions.DropDownMenu_OnClickTimerTexture, aura.Timer.Texture, true)
end

function PowaAurasOptions.DropDownMenu_OnClickTimerTexture(self)
	UIDropDownMenu_SetSelectedValue(self.owner, self.value)
	local aura = PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId]
	if not aura or not aura.Timer then
		return
	end
	aura.Timer.Texture = self.value
	aura.Timer:Dispose()
end

function PowaAurasOptions.DropDownStacksMenu_Initialize(owner)
	local aura = PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId]
	if not aura or not aura.Stacks then
		return
	end
	PowaAurasOptions:InitializeTextureDropdown(owner, PowaAurasOptions.DropDownMenu_OnClickStacksTexture, aura.Stacks.Texture, true)
end

function PowaAurasOptions.DropDownMenu_OnClickStacksTexture(self)
	UIDropDownMenu_SetSelectedValue(self.owner, self.value)
	local aura = PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId]
	if not aura or not aura.Stacks then
		return
	end
	aura.Stacks.Texture = self.value
	aura.Stacks:Dispose()
end

-- Ternary Logic
function PowaAurasOptions:DisableTernary(control)
	_G[control:GetName().."Text"]:SetTextColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b)
	control:Disable()
end

function PowaAurasOptions:TernarySetState(button, value)
	button:Enable()
	_G[button:GetName().."Text"]:SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b)
	if value == 0 then
		button:SetCheckedTexture("Interface\\Buttons\\UI-CheckBox-Check")
		button:SetChecked(0)
	elseif value == false then
		button:SetCheckedTexture("Interface\\RAIDFRAME\\ReadyCheck-NotReady")
		button:SetChecked(1)
	elseif value == true then
		button:SetCheckedTexture("Interface\\Buttons\\UI-CheckBox-Check")
		button:SetChecked(1)
	end
end

function PowaAurasOptions.Ternary_OnClick(self)
	local aura = PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId]
	if aura[self.Parameter] == 0 then
		aura[self.Parameter] = true
	elseif aura[self.Parameter] then
		aura[self.Parameter] = false
	else
		aura[self.Parameter] = 0
	end	
	PowaAurasOptions:TernarySetState(self, aura[self.Parameter])
	PowaAurasOptions.Ternary_CheckTooltip(self)
end

function PowaAurasOptions.Ternary_CheckTooltip(button)
	GameTooltip:SetOwner(button, "ANCHOR_RIGHT")
	GameTooltip:SetText(PowaAurasOptions.Text.TernaryAide[button.Parameter], nil, nil, nil, nil, 1)
	GameTooltip:AddLine(PowaAurasOptions.Text.aideTernary.."\n\124TInterface\\Buttons\\UI-CheckBox-Up:22\124t = "..PowaAurasOptions.Text.nomWhatever.."\n\124TInterface\\Buttons\\UI-CheckBox-Check:22\124t = "..PowaAurasOptions.Text.TernaryYes[button.Parameter].."\n\124TInterface\\RAIDFRAME\\ReadyCheck-NotReady:22\124t = "..PowaAurasOptions.Text.TernaryNo[button.Parameter], .8, .8, .8, 1)
	GameTooltip:Show()
end

function PowaAurasOptions:OptionTest()
	local aura = self.Auras[self.CurrentAuraId]
	local owner = _G["PowaIcone"..self.CurrentAuraId]
	if not aura or aura.buffname == "" or aura.buffname == " " then
		return
	end
	if aura.Showing then
		self:SetAuraHideRequest(aura)
		aura.Active = false
		if aura.customsoundend ~= "" then
			if aura.Debug then
				self:Message("Playing Custom end sound ", aura.customsoundend)
			end
			local pathToSound
			if string.find(aura.customsoundend, "\\") then
				pathToSound = aura.customsoundend
			else
				pathToSound = PowaGlobalMisc.PathToSounds..aura.customsoundend
			end
			PlaySoundFile(pathToSound, PowaMisc.SoundChannel)
		elseif aura.soundend > 0 then
			if PowaAurasOptions.Sound[aura.soundend] and string.len(PowaAurasOptions.Sound[aura.soundend]) > 0 then
				if aura.Debug then
					self:Message("Playing end sound ", PowaAurasOptions.Sound[aura.soundend])
				end
				if string.find(PowaAurasOptions.Sound[aura.soundend], "%.") then
					PlaySoundFile(PowaGlobalMisc.PathToSounds..PowaAurasOptions.Sound[aura.soundend], PowaMisc.SoundChannel)
				else
					PlaySound(PowaAurasOptions.Sound[aura.soundend], PowaMisc.SoundChannel)
				end
			end
		end
		if owner ~= nil then
			owner:SetAlpha(0.33)
		end
	else
		aura:CreateFrames()
		self.SecondaryAuras[aura.id] = nil
		self:DisplayAura(aura.id)
		self:RedisplayAura(aura.id)
		aura.Active = true
		if aura.customsound ~= "" then
			local pathToSound
			if string.find(aura.customsound, "\\") then
				pathToSound = aura.customsound
			else
				pathToSound = PowaGlobalMisc.PathToSounds .. aura.customsound
			end
			PlaySoundFile(pathToSound, PowaMisc.SoundChannel)
		elseif aura.sound > 0 then
			if PowaAurasOptions.Sound[aura.sound] and string.len(PowaAurasOptions.Sound[aura.sound]) > 0 then
				if string.find(PowaAurasOptions.Sound[aura.sound], "%.") then
					PlaySoundFile(PowaGlobalMisc.PathToSounds .. PowaAurasOptions.Sound[aura.sound], PowaMisc.SoundChannel)
				else
					PlaySound(PowaAurasOptions.Sound[aura.sound], PowaMisc.SoundChannel)
				end
			end
		end
		if owner ~= nil then
			owner:SetAlpha(1)
		end
	end
end

function PowaAurasOptions:OptionEditorTest()
	local aura = self.Auras[self.CurrentAuraId]
	if not aura or aura.buffname == "" or aura.buffname == " " then
		return
	end
	if not aura.Showing then
		aura.Active = true
		aura:CreateFrames()
		self.SecondaryAuras[aura.id] = nil
		self:DisplayAura(aura.id)
	end
end

function PowaAurasOptions:OptionTestAll()
	PowaAurasOptions:OptionHideAll(true)
	for id, aura in pairs(self.Auras) do
		if not aura.off then
			aura.Active = true
			aura:CreateFrames()
			self.SecondaryAuras[aura.id] = nil
			self:DisplayAura(aura.id)
			self:UpdatePreviewColor(self.Auras[self.CurrentAuraId])
		end
	end
	
end

function PowaAurasOptions:OptionHideAll(now)
	for id, aura in pairs(self.Auras) do
		aura.Active = false
		self:ResetDragging(aura, self.Frames[aura.id])
		if now then
			aura:Hide()
			if aura.Timer then
				aura.Timer:Hide()
			end
			if aura.Stacks then
				aura.Stacks:Hide()
			end
		else
			self:SetAuraHideRequest(aura)
			if aura.Timer then
				aura.Timer.HideRequest = true
			end
		end
	end
	--PowaBarConfigFrame:Hide()
end

function PowaAurasOptions:SetLockButtonText()
	if PowaMisc.Locked then
		PowaMainLockButtonText:SetText(PowaAurasOptions.Text.nomUnlock)
	else
		PowaMainLockButtonText:SetText(PowaAurasOptions.Text.nomLock)
	end
end

function PowaAurasOptions:ToggleLock()
	PowaMisc.Locked = not PowaMisc.Locked
	self:SetLockButtonText()
	self:RedisplayAuras()
end

function PowaAurasOptions:RedisplayAura(auraId)
	if not (self.VariablesLoaded and self.SetupDone) then
		return
	end
	local aura = self.Auras[auraId]
	if not aura then
		return
	end
	local showing = aura.Showing
	aura:Hide()
	aura.BeginAnimation = nil
	aura.MainAnimation = nil
	aura.EndAnimation = nil
	aura:CreateFrames()
	self.SecondaryAuras[aura.id] = nil
	if showing then
		self:DisplayAura(aura.id)
	end
end

function PowaAurasOptions:ResetSlotsToEmpty()
	for _, child in ipairs({PowaEquipmentSlotsFrame:GetChildren()}) do
		if child:IsObjectType("Button") then
			local slotName = string.gsub(child:GetName(), "Powa", "")
			if string.match(slotName, "Slot") then
				local slotId, emptyTexture = GetInventorySlotInfo(slotName)
				_G[child:GetName().."IconTexture"]:SetTexture(emptyTexture)
				child.SlotId = slotId
				child.Set = false
				child.EmptyTexture = emptyTexture
			end
		end
	end
end

function PowaAurasOptions:EquipmentSlotsShow()
	self:ResetSlotsToEmpty()
	local aura = self.Auras[self.CurrentAuraId]
	if not aura then
		return
	end
	for pword in string.gmatch(aura.buffname, "[^/]+") do
		pword = aura:Trim(pword)
		if string.len(pword) > 0 and pword ~= "???" then
			if pword == "Head" or pword == "Neck" or pword == "Shoulder" or pword == "Back" or pword == "Chest" or pword == "Shirt" or pword == "Tabard" or pword == "Wrist" or pword == "Hands" or pword == "Waist" or pword == "Legs" or pword == "Feet" or pword == "Finger0" or pword == "Finger1" or pword == "Trinket0" or pword == "Trinket1" or pword == "MainHand" or pword == "SecondaryHand" then
				local slotId = GetInventorySlotInfo(pword.."Slot")
				if slotId then
					local ok, texture = pcall(GetInventoryItemTexture, "player", slotId)
					if not ok then
						self:Message("Slot definitions are invalid!")
						self:ResetSlotsToEmpty()
						aura.buffname = ""
						return
					end
					if texture then
						_G["Powa"..pword.."SlotIconTexture"]:SetTexture(texture)
						_G["Powa"..pword.."Slot"].Set = true
					end
				end
			end
		end
	end
end

function PowaAurasOptions:EquipmentSlot_OnClick(slotButton)
	if not slotButton.SlotId then
		return
	end
	local aura = self.Auras[self.CurrentAuraId]
	if not aura then
		return
	end
	if slotButton.Set then
		_G[slotButton:GetName().."IconTexture"]:SetTexture(slotButton.EmptyTexture)
		slotButton.Set = false
	else
		local texture = GetInventoryItemTexture("player", slotButton.SlotId)
		if texture then
			_G[slotButton:GetName().."IconTexture"]:SetTexture(texture)
			slotButton.Set = true
		end
	end
	aura.buffname = ""
	local sep = ""
	for _, child in ipairs({PowaEquipmentSlotsFrame:GetChildren()}) do
		if child:IsObjectType("Button") then
			local slotName = string.gsub(child:GetName(), "Powa", "")
			if string.match(slotName, "Slot") then
				if child.Set then
					aura.buffname = aura.buffname..sep..string.gsub(slotName, "Slot", "")
					sep = "/"
				end
			end
		end
	end
end

function PowaAurasOptions:IconOnMouseWheel(delta)
	if delta then
		if delta > 0 then
			if PowaMisc.GroupSize < 8 then
				PowaMisc.GroupSize = PowaMisc.GroupSize + 1
			end
		else
			if PowaMisc.GroupSize > 1 then
				PowaMisc.GroupSize =  PowaMisc.GroupSize - 1
			end
		end
	end
	local min = self.CurrentAuraId
	local max = min + (PowaMisc.GroupSize - 1)
	for i = min, max do
		if self.Auras[i] then
			local slot = i - ((PowaAurasOptions.CurrentAuraPage - 1) * 24)
			local icon = _G["PowaIcone"..slot]
			if icon then
				icon:SetAlpha(1)
			end
			self:DisplayAura(i)
		end
	end
	if delta then
		if min > 1 then
			for i = 1, min - 1 do
				if self.Auras[i] then
					local aura = self.Auras[i]
					aura.Active = false
					self:ResetDragging(aura, self.Frames[i])
					aura:Hide()
					if aura.Timer then
						aura.Timer:Hide()
					end
					if aura.Stacks then
						aura.Stacks:Hide()
					end
					local slot = i - ((PowaAurasOptions.CurrentAuraPage - 1) * 24)
					local icon = _G["PowaIcone"..slot]
					if icon then
						icon:SetAlpha(0.33)
					end
				end
			end
		end
		for i = max + 1, PowaAurasOptions.CurrentAuraPage * 24 do
			if self.Auras[i] then
				local aura = self.Auras[i]
				aura.Active = false
				self:ResetDragging(aura, self.Frames[i])
				aura:Hide()
				if aura.Timer then
					aura.Timer:Hide()
				end
				if aura.Stacks then
					aura.Stacks:Hide()
				end
				local slot = i - ((PowaAurasOptions.CurrentAuraPage - 1) * 24)
				local icon = _G["PowaIcone"..slot]
				if icon then
					icon:SetAlpha(0.33)
				end
			end
		end
	end
	if PowaMisc.GroupSize == 1 then
		PowaHeader:SetText(self.Text.nomEffectEditor.." ("..self.CurrentAuraId..")")
	else
		PowaHeader:SetText(self.Text.nomEffectEditor.." ("..self.CurrentAuraId.." - "..self.CurrentAuraId + (PowaMisc.GroupSize - 1)..")")
	end
	PowaAurasOptions:UpdatePreviewColor(self.Auras[self.CurrentAuraId])
end

function PowaAurasOptions.SliderSetValues(slider, delta)
	if delta > 0 then
		slider:SetValue(slider:GetValue() + slider:GetValueStep())
	else
		slider:SetValue(slider:GetValue() - slider:GetValueStep())
	end
end

function PowaAurasOptions.SliderOnMouseUp(self, x, y, decimals, postfix)
	local frame = self:GetName()
	local min
	local max
	if x ~= 0 then
		min = format("%."..decimals.."f", (self:GetValue() - x))
	else
		local sliderMin = self:GetMinMaxValues()
		min = sliderMin
	end
	if y ~= 0 then
		max = format("%."..decimals.."f", (self:GetValue() + y))
	else
		local _, sliderMax = self:GetMinMaxValues()
		max = sliderMax
	end
	self:SetMinMaxValues(min, max)
	if postfix == nil then
		_G[frame.."Low"]:SetText(min)
		_G[frame.."High"]:SetText(max)
	else
		_G[frame.."Low"]:SetText(min..postfix)
		_G[frame.."High"]:SetText(max..postfix)
	end
	PowaAurasOptions:RedisplayAura(PowaAurasOptions.CurrentAuraId)
end

function PowaAurasOptions.SliderEditBoxSetValues(slider, editbox, x, y, decimals, endmark)
	local frame = slider:GetName()
	local slidervalue = slider:GetValue()
	local postfix = tostring(string.sub(editbox:GetText(), - 1))
	local value
	if postfix == "%" then
		value = tonumber(string.sub(editbox:GetText(), 1, - 2))
	else
		value = tonumber(editbox:GetText())
	end
	if value then
		value = format("%."..decimals.."f", value)
		local min
		local max
		if x ~= 0 then
			min = format("%."..decimals.."f", (value - x))
		else
			local sliderMin = slider:GetMinMaxValues()
			min = sliderMin
		end
		if y ~= 0 then
			max = format("%."..decimals.."f", (value + y))
		else
			local _, sliderMax = slider:GetMinMaxValues()
			max = sliderMax
		end
		slider:SetMinMaxValues(min, max)
		slider:SetValue(value)
		if endmark == nil then
			editbox:SetText(format("%."..decimals.."f", value))
		elseif endmark == "%" then
			editbox:SetText(format("%."..decimals.."f", value)..endmark)
		else
			if postfix == "%" then
				editbox:SetText(format("%."..decimals.."f", slider:GetValue()).."%")
			else
				editbox:SetText(format("%."..decimals.."f", slider:GetValue()))
			end
		end
		if endmark == "%" then
			_G[frame.."Low"]:SetText(min..endmark)
			_G[frame.."High"]:SetText(max..endmark)
		else
			_G[frame.."Low"]:SetText(min)
			_G[frame.."High"]:SetText(max)
		end
	else
		if x == 0 and y == 0 then
			local sliderMin, sliderMax = slider:GetMinMaxValues()
			slider:SetMinMaxValues(sliderMin, sliderMax)
		elseif x == 0 then
			local sliderMin = slider:GetMinMaxValues()
			slider:SetMinMaxValues(sliderMin, slidervalue + y)
		elseif y == 0 then
			local _, sliderMax = slider:GetMinMaxValues()
			slider:SetMinMaxValues(slidervalue - x, sliderMax)
		else
			slider:SetMinMaxValues(slidervalue - x, slidervalue + y)
		end
		slider:SetValue(slidervalue)
		if endmark == "%" then
			editbox:SetText(format("%."..decimals.."f", slidervalue)..endmark)
		else
			editbox:SetText(format("%."..decimals.."f", slidervalue))
		end
		if endmark == "%" then
			_G[frame.."Low"]:SetText((slidervalue - x)..endmark)
			_G[frame.."High"]:SetText((slidervalue + y)..endmark)
		else
			_G[frame.."Low"]:SetText(slidervalue - x)
			_G[frame.."High"]:SetText(slidervalue + y)
		end
	end
	PowaAurasOptions:RedisplayAura(PowaAurasOptions.CurrentAuraId)
end

function PowaAurasOptions.SliderEditBoxChanged(self)
	local frame = self:GetName()
	local slider = _G[string.sub(frame, 1, - 1 * (string.len("EditBox") + 1))]
	local postfix = tostring(string.sub(self:GetText(), - 1))
	if slider == PowaBarAuraSizeSlider then
		PowaAurasOptions.SliderEditBoxSetValues(slider, self, 0, 100, 0, "%")
	elseif slider == PowaBarAuraCoordXSlider or slider == PowaTimerCoordXSlider or slider == PowaStacksCoordXSlider then
		PowaAurasOptions.SliderEditBoxSetValues(slider, self, 700, 700, 0)
	elseif slider == PowaBarAuraCoordYSlider or slider == PowaTimerCoordYSlider or slider == PowaStacksCoordYSlider then
		PowaAurasOptions.SliderEditBoxSetValues(slider, self, 400, 400, 0)
	elseif slider == PowaModelPositionZSlider then
		PowaAurasOptions.SliderEditBoxSetValues(slider, self, 100, 100, 0)
	elseif slider == PowaModelPositionXSlider or slider == PowaModelPositionYSlider then
		PowaAurasOptions.SliderEditBoxSetValues(slider, self, 50, 50, 0)
	end
	if postfix == "%" and (slider == PowaBarAuraAlphaSlider or slider == PowaTimerSizeSlider or slider == PowaTimerAlphaSlider or slider == PowaStacksSizeSlider or slider == PowaStacksAlphaSlider) then
		local text = tonumber(string.sub(self:GetText(), 1, - 2))
		if text then
			text = text / 100
			slider:SetValue(text)
			self:SetText(format("%.0f", (slider:GetValue() * 100)).."%")
			local sliderlow, sliderhigh = slider:GetMinMaxValues()
			if text <= sliderlow or text >= sliderhigh then
				self:SetText(format("%.0f", (slider:GetValue() * 100)).."%")
			end
		else
			self:SetText(format("%.0f", (slider:GetValue() * 100)).."%")
		end
	elseif postfix == "%" and (slider == PowaBarAuraSizeSlider or slider == PowaBarAuraAnimSpeedSlider) then
		local text = tonumber(string.sub(self:GetText(), 1, - 2))
		if text then
			slider:SetValue(text)
			self:SetText(format("%.0f", (slider:GetValue())).."%")
			local sliderlow, sliderhigh = slider:GetMinMaxValues()
			if text <= sliderlow or text >= sliderhigh then
				self:SetText(format("%.0f", slider:GetValue()).."%")
			end
		else
			self:SetText(format("%.0f", slider:GetValue()).."%")
		end
	elseif postfix == "%" and slider == PowaBarThresholdSlider then
		local text = tonumber(string.sub(self:GetText(), 1, - 2))
		local aura = PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId]
		if text and aura.RangeType == "%" then
			slider:SetValue(text)
			self:SetText(format("%.0f", (slider:GetValue()))..aura.RangeType)
			local sliderlow, sliderhigh = slider:GetMinMaxValues()
			if text <= sliderlow or text >= sliderhigh then
				self:SetText(format("%.0f", slider:GetValue())..aura.RangeType)
			end
		else
			self:SetText(format("%.0f", slider:GetValue())..aura.RangeType)
		end
		PowaBarThresholdSliderEditBox:SetText(format("%.0f", PowaBarThresholdSlider:GetValue())..aura.RangeType)
	elseif slider == PowaBarAuraAlphaSlider or slider == PowaTimerSizeSlider or slider == PowaTimerAlphaSlider or slider == PowaStacksSizeSlider or slider == PowaStacksAlphaSlider then
		local text = tonumber(self:GetText())
		if text then
			text = text / 100
			slider:SetValue(text)
			self:SetText(format("%.0f", (slider:GetValue() * 100)).."%")
			local sliderlow, sliderhigh = slider:GetMinMaxValues()
			if text < sliderlow or text > sliderhigh then
				self:SetText(format("%.0f", (slider:GetValue() * 100)).."%")
			end
		else
			self:SetText(format("%.0f", (slider:GetValue() * 100)).."%")
		end
	elseif slider == PowaBarAuraSizeSlider or slider == PowaBarAuraAnimSpeedSlider then
		local text = tonumber(self:GetText())
		if text then
			slider:SetValue(text)
			self:SetText(format("%.0f", (slider:GetValue())).."%")
			local sliderlow, sliderhigh = slider:GetMinMaxValues()
			if text <= sliderlow or text >= sliderhigh then
				self:SetText(format("%.0f", slider:GetValue()).."%")
			end
		else
			self:SetText(format("%.0f", slider:GetValue()).."%")
		end
	elseif slider == PowaBarThresholdSlider then
		local text = tonumber(self:GetText())
		local aura = PowaAurasOptions.Auras[PowaAurasOptions.CurrentAuraId]
		if text then
			slider:SetValue(text)
			self:SetText(format("%.0f", (slider:GetValue()))..aura.RangeType)
			local sliderlow, sliderhigh = slider:GetMinMaxValues()
			if text <= sliderlow or text >= sliderhigh then
				self:SetText(format("%.0f", slider:GetValue())..aura.RangeType)
			end
		else
			self:SetText(format("%.0f", slider:GetValue())..aura.RangeType)
		end
		PowaBarThresholdSliderEditBox:SetText(format("%.0f", PowaBarThresholdSlider:GetValue())..aura.RangeType)
	elseif tonumber(postfix) == nil and slider == PowaBarAuraRotateSlider then
		local text = tonumber(string.sub(self:GetText(), 1, - 2))
		if text == nil then
			text = tonumber(string.sub(self:GetText(), 1, - 3))
		end
		if text then
			slider:SetValue(text)
			self:SetText(format("%.0f", slider:GetValue()).."°")
			local sliderlow, sliderhigh = slider:GetMinMaxValues()
			if text < sliderlow or text > sliderhigh then
				self:SetText(format("%.0f", slider:GetValue()).."°")
			end
		else
			self:SetText(format("%.0f", slider:GetValue()).."°")
		end
	elseif slider == PowaBarAuraRotateSlider then
		local text = tonumber(self:GetText())
		if text then
			slider:SetValue(text)
			self:SetText(format("%.0f", slider:GetValue()).."°")
			local sliderlow, sliderhigh = slider:GetMinMaxValues()
			if text < sliderlow or text > sliderhigh then
				self:SetText(format("%.0f", slider:GetValue()).."°")
			end
		else
			self:SetText(format("%.0f", slider:GetValue()).."°")
		end
	elseif slider == PowaBarAuraDeformSlider or slider == PowaBarAuraDurationSlider or slider == PowaTimerDurationSlider or slider == PowaTimerInvertAuraSlider then
		if tonumber(self:GetText()) ~= nil then
			slider:SetValue(tonumber(self:GetText()))
			self:SetText(format("%.2f", slider:GetValue()))
			local sliderlow, sliderhigh = slider:GetMinMaxValues()
			if tonumber(self:GetText()) < sliderlow or tonumber(self:GetText()) > sliderhigh then
				self:SetText(slider:GetValue())
			end
		else
			self:SetText(slider:GetValue())
		end
	else
		if tonumber(self:GetText()) ~= nil then
			slider:SetValue(tonumber(self:GetText()))
			self:SetText(format("%.0f", slider:GetValue()))
			local sliderlow, sliderhigh = slider:GetMinMaxValues()
			if tonumber(self:GetText()) < sliderlow or tonumber(self:GetText()) > sliderhigh then
				self:SetText(slider:GetValue())
			end
		else
			self:SetText(slider:GetValue())
		end
	end
end